我有以下ListView中使用自定义列表项:
I have the following ListView with a custom list item:
我想从其中切换按钮
点击列表项获得的TextView
值。
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);
}
}
通过这个code,我能够敬酒位置
的列表项的
包含切换按钮
点击。
当试图让文本1
或使用该code ID1
值:
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();
我总是得到的值文本1
从上的ListView
项。
什么想法?
在列表视图中onItemClick功能,粘贴以下code:
In onItemClick function of the listview, Paste the following code:
View parentView = (View) view.getParent();
textview1 = ((TextView) parentView
.findViewById(R.id.textview1)).getText().toString();
textview2 = ((TextView) parentView
.findViewById(R.id.textview2)).getText().toString();
textview3 = ((TextView) parentView
.findViewById(R.id.textview3)).getText().toString();
您可以使用上述code得到任何价值。
You can get any value using the above code..