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上打印此消息
答案 0 :(得分:2)
您可以将此代码用作其他活动。
Bundle extras = getIntent().getExtras();
String mValue = extras.getString("profileId");
TextView textView = new TextView(context);
textView.setText(mValue);
答案 1 :(得分:1)
你已经在意图中添加了字符串“你好吗”。所以现在你只需要在SharingActivity
:---
TextView textView = (TextView) this.findViewById(<ur textview id>);
String urText = getIntent.getExtras().get("extra");
textView.setText(urText);