I tried to create a custom ListView . ListView contains RelativeLayout , which contains TextView and a Switch . When you click on the switch, the switch should change from true to false (and vice versa).
This is my getView method:
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; }
This is my onClickListener:
list_quality.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
My onItemClickListener not called when I click on a TextView, Switch, or a space between two objects. When I press the switch, the switch works fine (the state changes). But my onItemClickListener not called. I tried to disable the clickable and focusable switch and TextView, but this also does not work.
Running setOnItemClickListeren.
source share