所以我的问题是标题:Android 是否有类似于 onListClickView 的 CheckBoxs 方法?
我有一个 onListClickView 方法来获取列表被触摸的位置,并从列表中的那个位置获取信息。
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
TextView label = ((TwoLineListItem) v).getText2();
String phoneNumber = label.getText().toString();
Toast.makeText(this, "Selected " + phoneNumber, Toast.LENGTH_SHORT).show();
}
这是我拥有的方法,但我不知道我可以使用类似的方法来为选中的框获取相同的信息。谁能阐明我遇到的这个问题?
最佳答案
您可以监听被点击的复选框:
CheckBox check = (CheckBox) findViewById(R.id.check_box);
check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override public void onCheckedChanged(CompoundButton button, boolean isChecked) {
// The checkbox has been clicked - do something interesting
}
});
关于Android 是否有类似于 onListClickView 的 CheckBoxes 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9551797/