Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7901593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:15:42+00:00 2026-06-03T09:15:42+00:00

I am new in Android and working on custom list view and it work

  • 0

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

 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 < 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<String, String> map = new HashMap<String, String>();

   //*** adding each child node to HashMap key => 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<?> 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);
        }
    }); 

My InvoiceList Adapter Class code

public class InvoiceListAdapter extends BaseAdapter {

//--private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;

public InvoiceListAdapter(ManageInvoice manageInvoice, ArrayList<HashMap<String, String>> 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()<=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<String, String> Invoice = new HashMap<String, String>();
    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;
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:15:44+00:00Added an answer on June 3, 2026 at 9:15 am
     public void onItemClick(AdapterView<?> parent, View view, int position, long id)
            {
                  // Starting new intent
                Intent in = new Intent(getApplicationContext(), PreviewInvoice.class);
                in.putExtra("myinvoiceid",invoiceList.get(position).get(TAG_INVOICE_ID));
                in.putExtra("uniquetoken", tokenid); // Actually I can't find your tokenId in HashMAp object
                startActivity(in);
            }
        }); 
    

    Because you are referring a static values of invoice_id in onItemClick(), instead just get positioned HashMap object from adapter and using it key get values of invoice_id.

    invoiceadapter.get(position) which gives yo a object for clicked position in ListView. And using key TAG_INVOICE_ID from HashMap object you can get the values of it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to android and working on accelerometer. I want to collect 20
I am new to Android and just started working with Android 4.0.3. which enables
I'm pretty new to Android dev and still working out a lot of things.
Is there any way, how to get new x86 image for Android emulator working
I am new to the android programming and my working environment is eclipse helio
I am new to JUnit and Android and good test documentation for working with
I've created a custom view by extending View, it draws fine but When i
Hello i m new to android and working on Radio application i gt stuck
I'm new to Android development and working on an Android application that requires the
I am using a custom title view and would like to show/hide a progressbar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.