我正在尝试创建一个包含一些细节的列表,其中可以单击项目本身,还有一个复选框,但是当我单击该复选框时,没有任何事情发生 - 即使它进入了点击监听器。
如果它不是和相反的话,应该检查复选框 - 开始...
这是我写的:
这是onCreate()
adapter = new CustomAdapter();
myList.setAdapter(adapter);
myList.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Intent intent = new Intent(getApplicationContext(),StudentDetailsActivity.class);
intent.putExtra("id",data.get(position).id);
startActivity(intent);
}
});
以下是适配器实现:
class CustomAdapter extends BaseAdapter
{
//@Override functions...
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
if(convertView == null){
LayoutInflater inflater = getLayoutInflater();
convertView = inflater.inflate(R.layout.row_layout,null);
}
TextView name = (TextView) convertView.findViewById(R.id.nameTextView);
TextView id = (TextView) convertView.findViewById(R.id.idTextView);
CheckBox checkBox = (CheckBox) convertView.findViewById(R.id.checkBox);
Student st = data.get(position);
name.setText(st.name);
id.setText(st.id);
checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CheckBox cb =(CheckBox) v.findViewById(v.getId());
cb.setChecked(!cb.isChecked());
}
});
return convertView;
}
}