Note that there are some explanatory texts on larger screens.

plurals
  1. POpreview/detail of single list on custom list view in android
    text
    copied!<p>I am new in Android and working on custom list view and it work perfectly , but the problem is when i clicked on a single list for show detail of list , every time it only show last list detail . within onItemClick method only last invoice id is passed every... here is code </p> <pre><code> try { //*** Getting Array of Attributes attributes = jsonreturn.getJSONObject(TAG_ATTRIBUTE); String status = attributes.getString(TAG_VALIDCODE); JSONObject invoices = jsonreturn.getJSONObject(TAG_INVOICELIST); JSONArray invoice = invoices.getJSONArray(TAG_INVOICE); if(status.equals("200")){ // looping through All Invoice for(int i = 0; i &lt; invoice.length(); i++) { JSONObject c = invoice.getJSONObject(i); //***** Storing each JSON item in variable JSONObject client = c.getJSONObject(TAG_CLIENT); String organization = client.getString(TAG_ORGANIZATION); String invoiceno = c.getString(TAG_ID); String date = c.getString(TAG_DATE); String currency = c.getString(TAG_CURRENCY); String outstanding = c.getString(TAG_OUTSTANDING); String invoice_status = c.getString(TAG_STATUS); invoice_id = c.getString(TAG_INVOICE_ID); //**** creating new HashMap HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); //*** adding each child node to HashMap key =&gt; value map.put(TAG_ORGANIZATION, organization); map.put(TAG_ID, invoiceno); map.put(TAG_DATE, date); map.put(TAG_CURRENCY, currency); map.put(TAG_OUTSTANDING, outstanding); map.put(TAG_STATUS, invoice_status); map.put(TAG_INVOICE_ID, invoice_id); //**** adding HashList to ArrayList invoiceList.add(map); } } else{ Toast.makeText(this, "Invalid Details", 1000).show(); } } catch (JSONException e) { e.printStackTrace(); } /** Updating parsed JSON data into ListView * */ InvoiceListAdapter invoiceadapter = new InvoiceListAdapter(this, invoiceList); mListView.setAdapter(invoiceadapter); //****** Launching new screen on Selecting Single ListItem mListView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { // getting values from selected ListItem //--String date = ((TextView) view.findViewById(R.id.date)).getText().toString(); //--String status = ((TextView) view.findViewById(R.id.invoicestatus)).getText().toString(); // Starting new intent Intent in = new Intent(getApplicationContext(), PreviewInvoice.class); in.putExtra("myinvoiceid", invoice_id); in.putExtra("uniquetoken", tokenid); //-- in.putExtra(TAG_DATE, date); //---in.putExtra(TAG_STATUS, status); startActivity(in); } }); </code></pre> <p>My InvoiceList Adapter Class code </p> <pre><code>public class InvoiceListAdapter extends BaseAdapter { //--private Activity activity; private ArrayList&lt;HashMap&lt;String, String&gt;&gt; data; private static LayoutInflater inflater=null; public InvoiceListAdapter(ManageInvoice manageInvoice, ArrayList&lt;HashMap&lt;String, String&gt;&gt; invoiceList) { //-- activity = manageInvoice; data=invoiceList; inflater = (LayoutInflater)manageInvoice.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } public int getCount() { if(null==data){ return 0; } return data.size(); } public Object getItem(int position) { if(null==data || data.size()&lt;=position){ return null; } return data.get(position); } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { View vi=convertView; if(convertView==null) vi = inflater.inflate(R.layout.invoice_list, null ); TextView title = (TextView)vi.findViewById(R.id.organization); TextView invoiceId = (TextView)vi.findViewById(R.id.invoice_id); TextView date = (TextView)vi.findViewById(R.id.date); TextView currency = (TextView)vi.findViewById(R.id.currency); TextView currencyvalue = (TextView)vi.findViewById(R.id.outstanding); TextView status = (TextView)vi.findViewById(R.id.invoice_status); // ImageView thumb_image=(ImageView)vi.findViewById(R.id.invoice_status); HashMap&lt;String, String&gt; Invoice = new HashMap&lt;String, String&gt;(); Invoice = data.get(position); // Setting all values in listview title.setText(Invoice.get(ManageInvoice.TAG_ORGANIZATION)); invoiceId.setText(Invoice.get(ManageInvoice.TAG_ID)); date.setText(Invoice.get(ManageInvoice.TAG_DATE)); currency.setText(Invoice.get(ManageInvoice.TAG_CURRENCY)); currencyvalue.setText(Invoice.get(ManageInvoice.TAG_OUTSTANDING)); status.setText(Invoice.get(ManageInvoice.TAG_STATUS)); return vi; } public JSONArray get(int position) { // TODO Auto-generated method stub return null; } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload