Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to assign different values to buttons in a listView - Android
    primarykey
    data
    text
    <p>I have a ListView Item that has 2 buttons in it. There are multiple ListView items so there are many buttons. How can I assign a different value to each button? What I want to happen is every button leads to the same activity, but when it goes to the new activity it sends a value that the button was assigned. Then the activity can handled the value. I want the values assigned to the buttons to be the same as what the text is set to, here is my baseAdapter</p> <pre><code>class CreateCommentLists extends BaseAdapter{ Context ctx_invitation; String[] listComments; String[] listNumbers; String[] listUsernames; public CreateCommentLists(String[] comments, String[] usernames, String[] numbers, DashboardActivity context) { super(); ctx_invitation = context; listComments = comments; listNumbers = usernames; listUsernames = numbers; } @Override public int getCount() { if(null == listComments) { return 0; } // TODO Auto-generated method stub return listComments.length; } @Override public Object getItem(int position) { // TODO Auto-generated method stub return listComments[position]; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub View v = null; try { String inflater = Context.LAYOUT_INFLATER_SERVICE; LayoutInflater li = (LayoutInflater)ctx_invitation.getSystemService(inflater); v = li.inflate(R.layout.list_item, null); TextView commentView = (TextView)v.findViewById(R.id.listComment); TextView NumbersView = (TextView)v.findViewById(R.id.listNumber); TextView usernamesView = (TextView)v.findViewById(R.id.listPostedBy); Button usernameButton = (Button)v.findViewById(R.id.listUsernameButton); Button numberButton = (Button)v.findViewById(R.id.listNumberButton); commentView.setText(listComments[position]); NumbersView.setText(listNumbers[position]); usernamesView.setText(listUsernames[position]); usernameButton.setText("Go to " + listUsernames[position]); numberButton.setText("Go to " + listNumbers[position]); } catch(Exception e) { e.printStackTrace(); } return v; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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