我有一个ListView
有两个TextView
,我需要获得TextVeiw
的价值,但却得错了数据。
例如,让我复制数据。
lstContent.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
//String selectedFromList = (lstContent.getItemAtPosition(arg2).toString());
//String selectedFromList = lstContent.getSelectedItem().toString();
//String txtselect = (TextView) findViewById(R.id.txtTitle);
//select = txtselect.getText().toString();
//Log.i("Log_five", select);
//Log.i("Log_five", selectedFromList);
}
});
我使用上面的评论代码,但所有这些代码都给我错误的数据。
答案 0 :(得分:2)
你可以试试这个:
lstContent.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
TextView txtView1 = (TextView) arg1.findViewById(R.id.txtTitle); //first TextView
String text1 = txtView1.getText().toString();
TextView txtView2 = (TextView) arg1.findViewById(R.id.txtView2); //second TextView
String text2 = txtView2.getText().toString();
Log.i("Log_five", text1);
Log.i("Log_five", text2);
}
});
希望它有所帮助。
答案 1 :(得分:1)
@Override
public void onItemClick(AdapterView<?> parent, View view, int postion, long id) {
String contactId = ((TextView) view.findViewById(R.id.cid)).getText().toString();