android listview添加点击事件OnItemclickListener没有反应,debug内部类OnItemClick没反应,急啊求大神
publicclassMainActivityextendsActivity{privateButtonbtnLight=null;privateButtonbtnHid...
public class MainActivity extends Activity {
private Button btnLight = null;
private Button btnHidden = null;
private ListView listView = null;
private ListAdapter mAdapter = null;
private List<Integer> dataList = null;
private TCPClient client = null;
private Handler handler = null;
private byte[] datas = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
handler = new Handler();
btnLight = (Button) findViewById(R.id.btn_light);
btnLight.setOnClickListener(new OpenLight());
btnHidden = (Button) findViewById(R.id.btn_hidden);
btnHidden.setOnClickListener(new CloseLight());
listView = (ListView) findViewById(R.id.list_view);
dataList = new ArrayList<Integer>();
initBox();
mAdapter = new ListAdapter(this, dataList);
listView.setAdapter(mAdapter);
listView.setOnItemClickListener(new OnItemClick());
}
class OnItemClick implements OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Vholder holder = (Vholder) arg0.getTag();
if(ListAdapter.getIsSelect().get(arg2)==0){
ListAdapter.getIsSelect().set(arg2, 1);
holder.box.toggle();
}else{
ListAdapter.getIsSelect().set(arg2, 0);
holder.box.toggle();
}
}
}
} 展开
private Button btnLight = null;
private Button btnHidden = null;
private ListView listView = null;
private ListAdapter mAdapter = null;
private List<Integer> dataList = null;
private TCPClient client = null;
private Handler handler = null;
private byte[] datas = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
handler = new Handler();
btnLight = (Button) findViewById(R.id.btn_light);
btnLight.setOnClickListener(new OpenLight());
btnHidden = (Button) findViewById(R.id.btn_hidden);
btnHidden.setOnClickListener(new CloseLight());
listView = (ListView) findViewById(R.id.list_view);
dataList = new ArrayList<Integer>();
initBox();
mAdapter = new ListAdapter(this, dataList);
listView.setAdapter(mAdapter);
listView.setOnItemClickListener(new OnItemClick());
}
class OnItemClick implements OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Vholder holder = (Vholder) arg0.getTag();
if(ListAdapter.getIsSelect().get(arg2)==0){
ListAdapter.getIsSelect().set(arg2, 1);
holder.box.toggle();
}else{
ListAdapter.getIsSelect().set(arg2, 0);
holder.box.toggle();
}
}
}
} 展开
2个回答
展开全部
看不到你的adapter,怀疑是item里有个button或者是类似的抢占了itemOnClick事件
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
看下你import进去的是哪个包的OnItemClickListener
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询