私はカスタムを作ろうとしていましたListView
。ListViewには、RelativeLayout
とを含むwhoが含まれTextView
ていますSwitch
。スイッチを押すと、スイッチはtrueからfalseに(またはその逆に)変更する必要があります。
これは私の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、または2つのオブジェクト間のスペースをクリックしても、Myは呼び出されません。スイッチを押すと、スイッチは正常に動作します(状態が変化します)。しかし、私onItemClickListener
は呼ばれていません。SwitchとTextViewを無効にしようとしましclickable
たfocusable
が、どちらも機能しません。
setOnItemClickListerenが実行されます。