Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid ListView get TextView value at the position where the toggle button is clicked
    primarykey
    data
    text
    <p>I have the following ListView with a custom list item:</p> <p><img src="https://i.stack.imgur.com/aimkd.png" alt="custom_list_item"></p> <p>I would like to get the <code>TextView</code> values from the list item where the <code>ToggleButton</code> is clicked. </p> <p>Here's the adapter that builds the list:</p> <pre><code> public class simpleAdapter extends SimpleAdapter { public simpleAdapter(Context context, ArrayList&lt;HashMap&lt;String, String&gt;&gt; list, int resource, String[] from, int[] to) { super(context, list, resource, from, to); // TODO Auto-generated constructor stub } @Override public View getView(final int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub // return super.getView(position, convertView, parent); LayoutInflater inflater = getLayoutInflater(); convertView = inflater.inflate(R.layout.user_campaigns_list_item, parent, false); tb_campaigns_list_toggle = (ToggleButton) convertView .findViewById(R.id.tb_campaigns_list_toggle); tb_campaigns_list_toggle.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub Toast.makeText(getApplicationContext(), String.valueOf(position), Toast.LENGTH_SHORT).show(); } }); return super.getView(position, convertView, parent); } } </code></pre> <p>With this code, I'm able to toast the <code>position</code> of the <code>list item</code> containing the <code>ToggleButton</code> clicked. When trying to get the <code>Text1</code> or <code>id1</code> values using this code:</p> <pre><code>TextView Text1 = (TextView)convertView.findViewById(R.id.Text1_id); //this line is outside the onClick(View v) method String Text1_value = Text1.getText().toString(); Toast.makeText(getApplicationContext(), Text1_value, Toast.LENGTH_SHORT).show(); </code></pre> <p>I'm always getting the value of the <code>Text1</code> from the last <code>ListView</code> item.</p> <p>any ideas?</p>
    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.
 

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