Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do i determine the items populating listview?
    primarykey
    data
    text
    <p>im a noob to android and i am populating a listview with an arrayilst and custom adapter. I want setup my listview onClickListener to execute commands based to the the items populating the listview. the listview is dynamically populated with items from the arraylist. I have tried the position and id parameters with no luck. Any help is greatly appreciated.</p> <p>How I instantiate listview, arraylist, and adapter</p> <pre><code> portfoliolist = (ListView) findViewById(R.id.listViewPortfolios); users = new ArrayList&lt;PortfolioRecord&gt;(); portfoliolist.setAdapter(new UserItemAdapter(this, R.layout.simplerow, users)); portfoliolist.setOnItemClickListener(this); </code></pre> <p>My Custom Adapter.</p> <pre><code>public class UserItemAdapter extends ArrayAdapter&lt;PortfolioRecord&gt; { private ArrayList&lt;PortfolioRecord&gt; users; public UserItemAdapter(Context context, int textViewResourceId, ArrayList&lt;PortfolioRecord&gt; users) { super(context, textViewResourceId, users); this.users = users; } @Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if (v == null) { LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.simplerow, null); } PortfolioRecord user = users.get(position); if (user != null) { TextView portfolioname = (TextView) v.findViewById(R.id.portfolioname); TextView currentvalue = (TextView) v.findViewById(R.id.currentvalue); if (portfolioname != null) { portfolioname.setText(user.portfolioname); } if(currentvalue != null) { currentvalue.setText("Current Value: " + user.currentvalue ); } } return v; } } public class PortfolioRecord { public String portfolioname; public String currentvalue; public PortfolioRecord(String portfolioname, String currentvalue) { this.portfolioname = portfolioname; this.currentvalue = currentvalue; } } </code></pre> <p>How i add items to arraylist:</p> <pre><code> user1 = new PortfolioRecord(pn10, denomination10+portfoliovalue10); users.add(user1); </code></pre> <p>I have added Usernull, user1 and user2 to my arraylist. How do i identify these items? I've tried the folowing code with no luck</p> <pre><code>public void onItemClick(AdapterView parent, View itemClicked, int position, long id) { TODO Auto-generated method stub switch(parent.getId()){ case R.id.listViewPortfolios: if(portfoliolist.getSelectedItem()==usernull){ openCustomDialog(); }else if(portfoliolist.getSelectedItem()==user1){ whichportfolio=1; }else if(portfoliolist.getSelectedItem()==user2){ whichportfolio=2; } break;}} </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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