【发布时间】:2013-01-25 14:48:56
【问题描述】:
我正在尝试自定义ListView。 ListView 包含一个RelativeLayout,其中包含一个TextView 和一个Switch。当您按下开关时,开关必须从真变为假(反之亦然)。
这是我的 getView 方法:
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null)
vi = inflater.inflate(R.layout.item_gproblem, null);
//vi.setClickable(true); Tried this
//vi.setFocusable(true);
TextView txt_comment_description = (TextView) vi
.findViewById(R.id.txt_comment_description);
txt_comment_description.setText(MyTasks.allGComments.get(position)
.getProblemDescription());
//txt_comment_description.setFocusable(false); Tried this
//txt_comment_description.setClickable(false);
Switch switch_comment = (Switch) vi.findViewById(R.id.switch_comment);
//switch_comment.setFocusable(false); Tried this
//switch_comment.setClickable(false);
//First time running getMyGComments returns a empty ArrayList
if (MyTasks.allCustomers.get(ServerData.myID - 1).getMyGComments()
.size() > position) {
switch_comment.setChecked(MyTasks.allCustomers
.get(ServerData.myID - 1).getMyGComments().get(position)
.isProblemValue());
}
return vi;
}
这是我的 onClickListener:
list_quality.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
//Do Something
}
});
当我单击 TextView、Switch 或两个对象之间的空间时,不会调用我的 onItemClickListener。当我按下开关时,开关正常工作(状态改变)。但是我的onItemClickListener 没有被调用。我试图禁用 Switch 和 TextView 的 clickable 和 focusable 但这也不起作用。
setOnItemClickListeren 被执行。
【问题讨论】:
标签: android listview onitemclicklistener