Android 是否有类似于 onListClickView 的 CheckBoxes 方法?

标签 android

所以我的问题是标题: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/

相关文章:

java - Android Nexus 6 模拟器上的 "Unfortunately, Launcher has stopped"

java - 安卓OGLES2.0 : All applications getting error

java - 在一个 PHP 中,android 尝试发送多种 json 格式,但只收到一种。我应该怎么办?

Android : Specifying the same Theme in styles. xml 和 styles-21.xml

android - Android将Eclipse迁移到Studio

android - 查看绘制完成回调

Android - 应用程序未运行。错误 : The minCompileSdk specified in a dependency's AAR metadata is greater than this module's compileSdkVersion

android - 使用 Google Fingerprint API 时,Samsung Galaxy S7 Edge 无法检测到指纹目录更改

安卓工作室 : ClassNotFoundException

android - Opencv Android 的代码优化