I have the following ListView with a custom list item:
I would like to get the TextView
values from the list item where the ToggleButton
is clicked.
Here's the adapter that builds the list:
public class simpleAdapter extends SimpleAdapter {
public simpleAdapter(Context context,
ArrayList<HashMap<String, String>> 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);
}
}
With this code, I'm able to toast the position
of the list item
containing the ToggleButton
clicked.
When trying to get the Text1
or id1
values using this 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();
I'm always getting the value of the Text1
from the last ListView
item.
any ideas?