将字符串从 activity 的列表视图传输到 android 的另一个列表视图

Transfer a string from list view on one activity to another in android

如何在单击时从 listView 传输字符串并在不同的 activity 中使用保存在变量中的字符串?

Intent intent = new Intent(fisrtActivity.this, secondActivity.class);
intent.putExtra(name of extra,String);
startActivity(intent);

进入secondActivity:

Intent i = getIntent()
String s = i.getStringExtra(name of extra);

是的,使用这样的代码:

lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    Intent i = new Intent(getBaseContext(), Activity2.class);
                    i.putExtra("var", (String)lv.getAdapter().getItem(position));
                    startActivity(i);
                }
            });

然后在 Activity2 中获取变量

Bundle bundle = getIntent().getExtras();
String var = bundle.getString("var");

按如下方式修改您的适配器 class 并尝试,

        @Override
        public void onItemClick(AdapterView<?> arg0, View v, int position,
            long arg3) {
        Intent intent = new Intent(context/getApplicationContext(),SecondActivity.class);
        intent.putExtra("value", your_list.get(position));
        context/getApplicationContext().startActivity(intent);
    }

为了得到值,

String yourString  = getIntent().getExtras().getString("value");

您可以通过编写代码在列表视图的项目点击事件中调用 next activity 来实现

Intent intent= new Intent(getBaseContext(),AnotherActivity.class);
            intent.putExtra("ANY_KEY", "YOUR STRING VALUE");
            startActivity(intent);

然后在其他 activity 的创建方法中通过

获取字符串的值
String str=getIntent().getStringExtra("ANY_KEY");