मुझे सेटर्स में डेटा मिल रहा है लेकिन गेटर्स में डेटा नहीं मिल रहा है। नीचे दिया गया कोड DatabaseHelper.java का है

  public  List<HouseModal> get_Working_Area_Structures_House(int limit, int offset,String searched_Str) {
    if(database == null){
        database = getWritableDatabase();
    }
    List<HouseModal> list_krd= new ArrayList<>();

    String selectQuery = "SELECT DISTINCT\n" +
            "\tWAS.Para_Structure_ID,\n" +
            "\tWAS.Para_Code || '   ' || CAST (WAS.Structure_No AS int) AS Structure_No,\n" +
            "\tST.Family_Count AS Families,\n" +
            "\tFM.Family_Members_Count AS Family_Members, \n" +
            "\t FM.Family_Migration AS Family_Migration\n" +
            "FROM\n" +
            "\t (\n" +
            "\t\t SELECT\n" +
            "\t\t\tP.Para_Code,\n" +
            "\t\t\tPS.Para_Structure_ID,\n" +
            "\t\t\tPS.Structure_No \n" +
            "\t\tFROM\n" +
            "\t\t\tPara_Structure AS PS\n" +
            "\t\tINNER JOIN  Working_Area_Structures AS WAS ON PS.Para_Structure_ID = WAS.Para_Structure_ID\n" +
            "\t\tINNER JOIN  Field_Station_Paras AS P ON PS.Para_ID = P.Para_ID \n" +
            "\t) AS WAS,\n" +
            "\t (\n" +
            "\tSELECT\n" +
            "\t\t\tKH.Para_Structure_ID,\n" +
            "\t\t\tCOUNT(DISTINCT KH.House_Hold_ID) AS Family_Count \n" +
            "\t\tFROM\n" +
            "\t\t\tKhandan_Register_Header AS KH\n" +
            "\t\tLEFT JOIN  Family_Visit_History AS FVH ON KH.House_Hold_ID = FVH.House_Hold_ID \n" +
            "\t\tWHERE\n" +
            "\t\t(FVH.Visit_Status = 0 OR FVH.Visit_Status IS NULL)\n" +
            "\t\t--AND ((date(FVH.Visit_Date) >= (SELECT date(Starting_Date) FROM Working_Cycle WHERE DATE('NOW') BETWEEN date(Starting_Date)AND date(Ending_Date)) AND date(FVH.Visit_Date) <= (SELECT date(Ending_Date) FROM Working_Cycle WHERE DATE('NOW') BETWEEN date(Starting_Date)AND date(Ending_Date))) OR date(FVH.Visit_Date) IS NULL) \n" +
            "\t\t--AND (KH.House_Hold_ID NOT IN (SELECT DISTINCT House_Hold_ID FROM Family_Visit_History WHERE Visit_Status = 1)) \n" +
            "\t\tGROUP BY KH.Para_Structure_ID\n" +
            "\t) AS ST , (\n" +
            "\t\t SELECT\n" +
            "\t\t\tKH.Para_Structure_ID,\n" +
            "\t\t\tCOUNT(\n" +
            "\t\t\t\tDISTINCT KD.Family_Member_ID\n" +
            "\t\t\t) AS Family_Members_Count, \n" +
            "\t\t\tfmr.Family_Migration_ID AS Family_Migration \n" +
            "\t\tFROM\n" +
            "\t\t\tKhandan_Register_Detail AS KD\n" +
            "\t\tINNER JOIN  Khandan_Register_Header AS KH ON KD.House_Hold_ID = KH.House_Hold_ID\n" +
            "\t\tLEFT JOIN  Family_Visit_History AS FVH ON KH.House_Hold_ID = FVH.House_Hold_ID \n" +
            "\t\tleft join Family_Migration_Register as fmr on KH.House_Hold_ID = fmr.House_Hold_ID \n" +
            "\t\tWHERE\n" +
            "\t\t\t(\n" +
            "\t\t\t\tFVH.Visit_Status = 0\n" +
            "\t\t\t\tOR FVH.Visit_Status IS NULL\n" +
            "\t\t\t) \n" +
            "\t\t--AND ((date(FVH.Visit_Date) >= (SELECT date(Starting_Date)FROM Working_Cycle WHERE DATE('NOW') BETWEEN date(Starting_Date)AND date(Ending_Date)) \n" +
            "\t\t--AND date(FVH.Visit_Date) <= (SELECT date(Ending_Date) FROM Working_Cycle WHERE DATE('NOW') BETWEEN date(Starting_Date)AND date(Ending_Date))) OR date(FVH.Visit_Date) IS NULL) \n" +
            "\t\tAND (KH.House_Hold_ID NOT IN (SELECT DISTINCT House_Hold_ID FROM Family_Visit_History WHERE Visit_Status = 1 )) \n" +
            "\t\tGROUP BY\n" +
            "\t\t\tKH.Para_Structure_ID \n" +
            "\t) AS FM \n" +
            "WHERE\n" +
            "\tWAS.Para_Structure_ID = ST.Para_Structure_ID \n" +
            "\n" +
            "AND WAS.Para_Structure_ID = FM.Para_Structure_ID\n" +
            "\n" +
            "AND ST.Para_Structure_ID = FM.Para_Structure_ID\n" +
            "\n";
    if (!searched_Str.trim().equals("null") && !searched_Str.trim().equals(""))
    {
        selectQuery += " And WAS.Structure_No like '%"+searched_Str+"%'";
    }
    selectQuery += " ORDER BY WAS.Para_Code, Cast(WAS.Structure_No As int) limit "+limit+" offset "+offset;

    try{
        Cursor cursor = database.rawQuery(selectQuery, null);
        if (cursor.getCount() > 0) {
            if (cursor != null && cursor.moveToFirst()) {
                do {
                    HouseModal dkrd = new HouseModal();
                    dkrd.setStructureID(cursor.getInt(0));
                    dkrd.setStructureNo(cursor.getString(1));
                    dkrd.setFamilies(cursor.getInt(2));
                    dkrd.setMembers(cursor.getInt(3));
                    dkrd.setFamilyMigrationID(cursor.getString(4));
                    list_krd.add(dkrd);
                } while (cursor.moveToNext());
            }
        }
        cursor.close();
    }
    catch (Exception e){
        e.printStackTrace();
    }
    return list_krd;
}

जैसा कि आप स्क्रीनशॉट 1 में देख सकते हैं, मुझे setFamilyMigrationID में परिणाम मिल रहा है।

लेकिन गेटटर में परिणाम नहीं मिल रहा है जो एक एडपेटर में सेट है

package pk.softech.sukh.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

import pk.softech.sukh.R;
import pk.softech.sukh.modal.HouseModal;

public class HouseAdapter extends ArrayAdapter<HouseModal> {

    private View root;

    public HouseAdapter(Context context,List<HouseModal> items) {
        super(context,R.layout.view_house_item);
    }

    class ViewHolder{
        TextView totalAfrad,totalKhandan,structureID,migratedFamilies;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ViewHolder holder;

        HouseModal item = getItem(position);
        if(view == null){
            view = LayoutInflater.from(getContext()).inflate(R.layout.view_house_item,null);
            holder = new ViewHolder();
            holder.structureID = (TextView) view.findViewById(R.id.structureID);
            holder.totalAfrad = (TextView) view.findViewById(R.id.totalAfrad);
            holder.totalKhandan = (TextView) view.findViewById(R.id.totalKhandan);
            holder.migratedFamilies = (TextView) view.findViewById(R.id.families);

            view.setTag(holder);
        }
        else{
            holder = (ViewHolder) view.getTag();
        }

        holder.structureID.setText(String.valueOf(item.getStructureNo()));
        holder.totalKhandan.setText(String.valueOf(item.getFamilies()));
        holder.totalAfrad.setText(String.valueOf(item.getMembers()));
        holder.migratedFamilies.setText(String.valueOf(item.getFamilyMigrationID()));

        return view;
    }
}

लेकिन मुझे परिणाम नहीं मिल रहा है GetFamilyMigrationID में सेट करें जैसा कि आप स्क्रीनशॉट में देख सकते हैं 2

नीचे मोडल कोड है

package pk.softech.sukh.modal;

public class HouseModal {

    private int structureID, families,members;
    private String migrationID;

    private String houseHoldID;
    private String structureNo ;


    public String getFamilyMigrationID() {
        return migrationID;
    }

    public void setFamilyMigrationID(String migrationID) {
        this.migrationID = migrationID;
    }

    public String getStructureNo() {
        return structureNo;
    }

    public void setStructureNo(String structureNo) {
        this.structureNo = structureNo;
    }


    public int getStructureID() {
        return structureID;
    }

    public void setStructureID(int structureID) {
        this.structureID = structureID;
    }

    public int getFamilies() {
        return families;
    }

    public void setFamilies(int families) {
        this.families = families;
    }

    public int getMembers() {
        return members;
    }

    public void setMembers(int members) {
        this.members = members;
    }

    public String getHouseHoldID() {
        return houseHoldID;
    }

    public void setHouseHoldID(String houseHoldID) {
        this.houseHoldID = houseHoldID;
    }
}
2
Shahzaib Khan 3 अक्टूबर 2018, 14:16

2 जवाब

सबसे बढ़िया उत्तर

आपको सूची सेट करने की आवश्यकता है सुपर () विधि को कोड के नीचे आज़माएं, यह आपकी समस्या का समाधान करेगा

public HouseAdapter(Context context,List<HouseModal> items) {
        super(context,R.layout.view_house_item,items);
    }
1
Ganesh Gudghe 3 अक्टूबर 2018, 14:33

कर्सर का उपयोग करके अपना कॉलम इंडेक्स प्राप्त करने के लिए आपको getColumnIndex() इस पद्धति का उपयोग करने की आवश्यकता है।

नीचे दिए गए कोड का प्रयोग करें:

HouseModal dkrd = new HouseModal();
dkrd.setStructureID(cursor.getInt(cursor.getIndex("column name here"));
dkrd.setStructureNo(cursor.getString(cursor.getIndex("column name here")));
dkrd.setFamilies(cursor.getInt(cursor.getIndex("column name here")));
dkrd.setMembers(cursor.getInt(cursor.getIndex("column name here")));
dkrd.setFamilyMigrationID(cursor.getString(cursor.getIndex("column name here")));

आपके कोड के बजाय:

HouseModal dkrd = new HouseModal();
                dkrd.setStructureID(cursor.getInt(0));
                dkrd.setStructureNo(cursor.getString(1));
                dkrd.setFamilies(cursor.getInt(2));
                dkrd.setMembers(cursor.getInt(3));
                dkrd.setFamilyMigrationID(cursor.getString(4));

getColumnIndex (स्ट्रिंग कॉलमनाम) के बारे में अधिक जानकारी:

दिए गए कॉलम नाम के लिए शून्य-आधारित अनुक्रमणिका देता है, या -1 यदि कॉलम मौजूद नहीं है। यदि आप उम्मीद करते हैं कि कॉलम मौजूद रहेगा इसके बजाय getColumnIndexOrThrow(String), जो त्रुटि को और स्पष्ट कर देगा।

मापदंडों

कॉलमनाम: लक्ष्य कॉलम का नाम।

1
Jeel Vankhede 3 अक्टूबर 2018, 14:22