我在我的xml文件中创建了一个复选框。我试图在checkBox的文本上设置onClickListener,但是我找不到真正的解决方案。换句话说,我希望能够点击复选框(使复选框可选),并点击文本以协议期限开启新的活动。谢谢。在复选框文本上设置onClickListener
main.xml中
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I agree to the Terms of Agreement."
android:textColor="#CC000000"
android:checked="true"/>
这是下面的代码我尝试,但它只会导致崩溃。
CheckBox checkBox1 = (CheckBox) findViewById(R.id.checkBox1);
Button termsOfAgreement = (Button) checkBox2.getText();
....
termsOfAgreement.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
//Launch activity
}
});
是的,我已经考虑到了,并打算作为我最后的解决方案。如果可能的话,最好从checkBox中执行它。想知道是否有任何可能的方法。 – ChallengeAccepted
不,不存在 – tyczj
谢谢。我继续做,并做你的建议。可能不是答案,但它是最好的选择。 – ChallengeAccepted