我有一个ListView
,每列包含三个TextViews
(出于格式原因)。
我遇到的问题是调用onItemClick
方法时我需要返回所有三个TextViews
的值,这是我无法实现的:
((TextView)view.).getText().toString();
答案 0 :(得分:2)
尝试将id分配给TextViews,然后使用findViewById在视图中找到它们的行项目。例如:
public void onItemClick(AdapterView<?> parent, View child, int position, long id) {
TextView titleTextView = (TextView)child.findViewById(R.id.textview_title);
TextView subtitleTextView = (TextView)child.findViewById(R.id.textview_subtitle);
TextView dateTextView = (TextView)child.findViewById(R.id.textview_date);
// Do the rest of your processing here
}
答案 1 :(得分:1)
访问TextView
中的每个ListView
,如下所示:
listView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View viewItem, int position, long arg3) throws NullPointerException{
TextView one = (TextView)parent.getChildAt(position-listView.getFirstVisiblePosition()).findViewById(R.id.tvone);
String tvone = one.getText().toString();
TextView two = (TextView)parent.getChildAt(position-listView.getFirstVisiblePosition()).findViewById(R.id.tvtwo);
String tvtwo = two.getText().toString();
TextView three = (TextView)parent.getChildAt(position-listView.getFirstVisiblePosition()).findViewById(R.id.tvthree);
String tvthree = three.getText().toString();
}
}
答案 2 :(得分:0)
最后,我发现这很完美:
String item = ((TextView)view.findViewById(R.id.TYPE_CELL)).getText().toString();