我试图做一个自定义ListView
。ListView 包含一个RelativeLayout
who 包含 aTextView
和 a 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
}
});
onItemClickListener
当我单击 TextView、Switch 或两个对象之间的空间时,不会调用My 。当我按下开关时,开关动作正常(状态改变)。但我onItemClickListener
的没有被调用。我试图禁用Switchclickable
和focusable
TextView ,但这也不起作用。
执行 setOnItemClickListeren。