Android复选框在一个活动中选中,然后在另一个活动中将显示文本,通知该复选框已被选中



所以我有一个带有复选框和按钮的活动,还有一个带有文本视图的活动。当我选中复选框并单击按钮时,按钮会调用startActivty(intent),它会用文本视图启动其他活动,并应该用文本通知用户复选框已被选中。我该怎么做?

在开始另一个活动之前,pass复选框被选中并不是捆绑中的extran,假设1被选中。

Intent i = new Intent(this, FindAndroidActivity.class);
i.putExtra("Checkbox","1");

在您的其他活动中,获取该值

Bundle extras = getIntent().getExtras();
if(extras !=null) {
    String value = extras.getString("Checkbox");
 //Check if value is '1', if so, it is checked and add whatever text you want to textbox here.
}
Intent intent=new Intent();
intent.putExtra("Checked",true);

然后带着这个意图开始你的活动。在第二个活动中,覆盖activity.onStart()

@Override
public void onStart(){
    super.onStart();
    Bundle bundle=getIntent.getExtras();
    if(bundle!=null){
        if(bundle.getBoolean("Checked")) /*do your stuff*/
    }
}

最新更新