-2

我使用 OnItemClickListener 从列表视图中选择一个项目,如下所示:

    listView.setTextFilterEnabled(true);

    final TextView disp = (TextView) findViewById(R.id.textView1); 
    listView.setOnItemClickListener(new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> arg0, View view, int position,long id) {
        String temp = (String) listView.getItemAtPosition(position);
        disp.setText(temp);// display on screen
        Toast.makeText(getBaseContext(),temparr.get(position),Toast.LENGTH_SHORT).show();
    }
    });

现在我想在另一个活动中显示结果。我怎样才能实现它?

4

4 回答 4

0
 @Override
public void onItemClick(AdapterView<?> arg0, View view, int position,long id) {
String temp = (String) listView.getItemAtPosition(position);
disp.setText(temp);// display on screen

Bundle bund = new Bundle();

bund.putString("YourKey",disp);

Intent intent = new Intent(CurrentActivity.this,NextActivity,class);
intent.putExtra(bund);

startActivity(intent);

} });

NextActivity.class

Bundle data = getIntent().getExtras();

if(data!=null)
   String temp = data.getString("YourKey");
于 2013-09-01T16:16:42.493 回答
0

使用意图

@Override
public void onItemClick(AdapterView<?> arg0, View view, int position,long id) {
    String temp = (String) listView.getItemAtPosition(position);
    // or String temp = (String) arg0.getItemAtPosition(position);
    disp.setText(temp);// display on screen
    Intent i = new Intent(ActivityName.this,SecondActivity,class);
    i.putExtra("key",temp);
}
});

在SecondActivity

有一个文本视图

Bundle extras = getIntent().getExtras();
if(extras!=null)
{
     String value = extras.getString("key");
     // textview.setText(value);
}  
于 2013-09-01T16:11:25.450 回答
0

您可以将“putExtra”添加到意图对象

intent.putExtra("listViewItem", temp);
startActivity(intent);

并在第二个活动中恢复它使用:

listViewItem= getIntent().getExtras().getString("listViewItem");
于 2013-09-01T16:11:50.747 回答
0

把它写在你的点击监听器中

Intent myIntent = new Intent(YourCurentActivity.this, SecondActivity.class);
myIntent.putExtra("key", temp);
startActivity(myIntent);

在第二个活动中执行此操作-

   Bundle extras = getIntent().getExtras();
if(extras!=null)
{
 String temp = extras.getString("key");
 textview.setText(temp);
}   
于 2013-09-01T16:12:10.747 回答