【问题标题】:How to take a string from listview and send it to another activity on text view如何从列表视图中获取字符串并将其发送到文本视图上的另一个活动
【发布时间】:2012-10-20 04:38:58
【问题描述】:
ListView lv;
String values[] = new String[]{"Hello How r u","I am Fine"};
lv=(ListView)findViewById(R.id.listView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, festival);
lv.setOnItemClickListener(new OnItemClickListener() { 
    public void onItemClick(AdapterView<?> arg0,View arg1,int position,long arg3) {
        if(position==0) {
            Intent i=new Intent(MainActivity.this ,SharingActivity.class );
            i.putExtra("extra", values[0]);
            startActivity(i);
        }
    }
}

lv.setAdapter(adapter);

嗨,这是我的 MainActivity。我想使用 Intent 向 SharingActivity 发送“Hello How are you”。如何?在SharingActivity 中,我有一个TextView。我想在 TextView 上打印这条消息

【问题讨论】:

  • stackoverflow.com/questions/12971252/…。你应该看看这个链接。
  • 发布代码时请使用代码标签。您的帖子现在非常难以阅读。
  • @ShailModi 首先接受一些答案,然后我可以帮助你。
  • 如果您有答案,请接受。如果您不接受答案,人们以后不会想回答您的问题

标签: android android-layout android-listview textview


【解决方案1】:

您可以将此代码用于其他活动。

 Bundle extras = getIntent().getExtras();
    String mValue = extras.getString("profileId");
    TextView textView = new TextView(context);
    textView.setText(mValue);

【讨论】:

    【解决方案2】:

    你已经在意图中添加了字符串“你好吗”。所以现在你只需要在你的SharingActivity 中这样做:---

    TextView textView = (TextView) this.findViewById(<ur textview id>);
    String urText = getIntent.getExtras().get("extra");
    textView.setText(urText);
    

    【讨论】:

      猜你喜欢
      • 2015-06-30
      • 1970-01-01
      • 1970-01-01
      • 2012-09-16
      • 2019-05-22
      • 1970-01-01
      • 2018-11-26
      • 2020-03-28
      • 1970-01-01
      相关资源
      最近更新 更多