mercredi 24 juin 2015

when i checked check box,How to get related row data in android?

I have a ListViewwith custom row. In custom row i have one checkBox and two textviews. Like that i have 5 custom rows in Listview. Now i checked first row check box and second row check box.Now i need to display those checked row's data in another screen. snippet here

public class ProcessPurchaseOrder extends Activity{
HashMap<String, String> ProcessPOHashMap;
ArrayList<HashMap<String,String>> arListHashMap;
ListView processPOListView;
ProcessPOAdapter processPOAdapter;

@InjectView(R.id.processPONextBtn) protected Button procesPONxtBtn;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.process_po);
    ButterKnife.inject(this);
    procesPONxtBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Intent drugSupplier = new Intent(ProcessPurchaseOrder.this, DrugSupplierActivity.class);
            startActivity(drugSupplier);

        }
    });

    arListHashMap = new ArrayList<HashMap<String, String>>();
    ProcessPOHashMap = new HashMap<String, String>();
    ProcessPOHashMap.put("DrugName", "crocin");
    ProcessPOHashMap.put("QtyAvail", "300");
    ProcessPOHashMap.put("QtyOrderd", "500");
    arListHashMap.add(ProcessPOHashMap);

    ProcessPOHashMap = new HashMap<String, String>();
    ProcessPOHashMap.put("DrugName", "zintac");
    ProcessPOHashMap.put("QtyAvail", "200");
    ProcessPOHashMap.put("QtyOrderd", "400");
    arListHashMap.add(ProcessPOHashMap);

    ProcessPOHashMap = new HashMap<String, String>();
    ProcessPOHashMap.put("DrugName", "anacin");
    ProcessPOHashMap.put("QtyAvail", "400");
    ProcessPOHashMap.put("QtyOrderd", "400");
    arListHashMap.add(ProcessPOHashMap);

    ProcessPOHashMap = new HashMap<String, String>();
    ProcessPOHashMap.put("DrugName", "tapic-EM");
    ProcessPOHashMap.put("QtyAvail", "400");
    ProcessPOHashMap.put("QtyOrderd", "400");
    arListHashMap.add(ProcessPOHashMap);

    ProcessPOHashMap = new HashMap<String, String>();
    ProcessPOHashMap.put("DrugName", "omnacartil 5mg");
    ProcessPOHashMap.put("QtyAvail", "400");
    ProcessPOHashMap.put("QtyOrderd", "400");
    arListHashMap.add(ProcessPOHashMap);

    ProcessPOHashMap = new HashMap<String, String>();
    ProcessPOHashMap.put("DrugName", "maxiguard 250mg");
    ProcessPOHashMap.put("QtyAvail", "400");
    ProcessPOHashMap.put("QtyOrderd", "400");
    arListHashMap.add(ProcessPOHashMap);

    ProcessPOHashMap = new HashMap<String, String>();
    ProcessPOHashMap.put("DrugName", "c-led");
    ProcessPOHashMap.put("QtyAvail", "400");
    ProcessPOHashMap.put("QtyOrderd", "400");
    arListHashMap.add(ProcessPOHashMap);

    ProcessPOHashMap = new HashMap<String, String>();
    ProcessPOHashMap.put("DrugName", "1000 mcg");
    ProcessPOHashMap.put("QtyAvail", "400");
    ProcessPOHashMap.put("QtyOrderd", "400");
    arListHashMap.add(ProcessPOHashMap);

    ProcessPOHashMap = new HashMap<String, String>();
    ProcessPOHashMap.put("DrugName", "omikind");
    ProcessPOHashMap.put("QtyAvail", "400");
    ProcessPOHashMap.put("QtyOrderd", "400");
    arListHashMap.add(ProcessPOHashMap);

    ProcessPOHashMap = new HashMap<String, String>();
    ProcessPOHashMap.put("DrugName", "nice");
    ProcessPOHashMap.put("QtyAvail", "900");
    ProcessPOHashMap.put("QtyOrderd", "100");
    arListHashMap.add(ProcessPOHashMap);

    ProcessPOHashMap = new HashMap<String, String>();
    ProcessPOHashMap.put("DrugName", "omez");
    ProcessPOHashMap.put("QtyAvail", "400");
    ProcessPOHashMap.put("QtyOrderd", "400");
    arListHashMap.add(ProcessPOHashMap);

    ProcessPOHashMap = new HashMap<String, String>();
    ProcessPOHashMap.put("DrugName", "tellmekind 40mg");
    ProcessPOHashMap.put("QtyAvail", "400");
    ProcessPOHashMap.put("QtyOrderd", "400");
    arListHashMap.add(ProcessPOHashMap);

    ProcessPOHashMap = new HashMap<String, String>();
    ProcessPOHashMap.put("DrugName", "Amlokind-at");
    ProcessPOHashMap.put("QtyAvail", "400");
    ProcessPOHashMap.put("QtyOrderd", "400");
    arListHashMap.add(ProcessPOHashMap);

    ProcessPOHashMap = new HashMap<String, String>();
    ProcessPOHashMap.put("DrugName", "gatimac 400mg");
    ProcessPOHashMap.put("QtyAvail", "400");
    ProcessPOHashMap.put("QtyOrderd", "400");
    arListHashMap.add(ProcessPOHashMap);

    ProcessPOHashMap = new HashMap<String, String>();
    ProcessPOHashMap.put("DrugName", "nupenta-DSR");
    ProcessPOHashMap.put("QtyAvail", "400");
    ProcessPOHashMap.put("QtyOrderd", "400");
    arListHashMap.add(ProcessPOHashMap);
    processPOListView = (ListView) findViewById(R.id.processPOListView);
    processPOAdapter= new ProcessPOAdapter(ProcessPurchaseOrder.this, arListHashMap);
    processPOListView.setAdapter(processPOAdapter);

}}`

AdapterClass is here

public class ProcessPOAdapter extends BaseAdapter {
private Activity activity;
Activity context;
ArrayList<HashMap<String, String>> data;
HashMap<String, String> mapdata;

public ProcessPOAdapter(Activity context, ArrayList<HashMap<String, String>> data) {
    super();
    this.context = context;
    this.data = data;

}
@Override
public int getCount() {
    return data.size();
}

@Override
public Object getItem(int position) {
    return position;
}

@Override
public long getItemId(int position) {
    return position;
}

private class ViewHolder {
    CheckBox drugCheck;
    TextView drugName;
    TextView qtyAvail;
    TextView qtyOrderd;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {

    final ViewHolder holder;
    LayoutInflater inflater = context.getLayoutInflater();
    mapdata = new HashMap<String, String>();
    mapdata = data.get(position);
    if (convertView == null) {
        convertView = inflater.inflate(R.layout.process_po_row, null);
        holder = new ViewHolder();
        holder.drugCheck = (CheckBox) convertView.findViewById(R.id.chkBoxDrugs);
        holder.drugName = (TextView) convertView.findViewById(R.id.txtDrugValue);
        holder.qtyAvail = (TextView) convertView.findViewById(R.id.txtQtyAvailValue);
        holder.qtyOrderd = (TextView) convertView.findViewById(R.id.txtQtyOrderdValue);
        convertView.setTag(holder);


    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    holder.drugName.setText(mapdata.get("DrugName"));
    holder.qtyAvail.setText(mapdata.get("QtyAvail"));
    holder.qtyOrderd.setText(mapdata.get("QtyOrderd"));
    return convertView;
}

}




Aucun commentaire:

Enregistrer un commentaire