Android 选中复选框将项目发送到不同的活动

Android 选中复选框将项目发送到不同的活动,android,android-listview,android-activity,android-checkbox,Android,Android Listview,Android Activity,Android Checkbox,在我的应用程序中,选中复选框后,我希望ListView中的项目转到另一个活动中的另一个ListView。请帮助我或给我一些如何做这方面的建议。谢谢你的帮助 public class Check extends Activity{ CheckBox check; TextView tvItem; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState

在我的应用程序中,选中复选框后,我希望ListView中的项目转到另一个活动中的另一个ListView。请帮助我或给我一些如何做这方面的建议。谢谢你的帮助

public class Check extends Activity{

CheckBox check;
TextView tvItem;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    check = (CheckBox) findViewById(R.id.checkBox1);
    tvItem = (TextView) findViewById(R.id.tvItem);
    check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if(isChecked){

            }else{

            }

        }
    });
}



}

我应该在if和else中输入什么代码。

基本上,您需要为复选框设置onClickedListener,然后启动活动,传递足够的信息,以便在ListView设置正确的情况下启动新活动。您可能需要切换复选框的状态,以防万一我已经包含了相应的代码,如果出现问题,请将其删除

checkBox.setOnClickListener(new OnClickListener() {
    @Override
    void onClick(View v) {
        checkedBox.toggle(); //Remove if check box is toggled correctly

        Intent intent=new Intent(MainActivity.this,OtherActivity.class);
        intent.putExtra("data",someData);
        startActivity(intent);
    }
}
其他活动检查意图,如:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Get the message from the intent
    Intent intent = getIntent();
    String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

    //Magic happens here.
}

有关更多详细信息,请仔细阅读本文。

您可以捆绑信息(如项目名称),并通过检查或单击按钮,通过意图将其发送到另一个活动

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu);

        final String MSTag = "MSTag"; //declare this string as your tag
            String itemName = YOUR_LIST_ITEM_NAME

...
       Intent myIntent = new Intent(this, YOUR_NEW_ACTIVITY.class);  
       myIntent.putExtra(MSTag, itemName); // add your tag and the item name to your intent.

       startActivity(m1Intent);
然后,在您的新活动中:

Bundle intent = getIntent().getExtras(); // this gets your added extras from the previous activity
myTag = intent.getString("MSTag"); // matches on your tag, and gets the string value
String itemName = myTag;
...

然后将您的项目添加到新活动的列表视图中

如果不查看您的代码,您将很难获得帮助。