0

我有一个列表视图,我想将列表视图的文本传递给另一个活动的编辑文本。你能帮忙吗?

    public class MainActivity extends Activity {

    private ListView listView1;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Weather weather_data[] = new Weather[]
        {
            new Weather(R.drawable.weather_cloudy, "Cloudy"),
            new Weather(R.drawable.weather_showers, "Showers"),
            new Weather(R.drawable.weather_snow, "Snow"),
            new Weather(R.drawable.weather_storm, "Storm"),
            new Weather(R.drawable.weather_sunny, "Sunny")
        };

        WeatherAdapter adapter = new WeatherAdapter(this, 
      R.layout.listview_item_row, weather_data);


        listView1 = (ListView)findViewById(R.id.listView1);

        View header = (View)getLayoutInflater().inflate(R.layout.listview_header_row, null);
        listView1.addHeaderView(header);

        listView1.setAdapter(adapter);
}

当我单击第一行时,下一个活动将在编辑文本中显示“多云”。

4

1 回答 1

1

You can create a listview onItemClickListener for ur listview and when user clicks on list item/row u can get the text from that row and u can pass it to next Activity that u r going to call and u r passing data via bundle and Intent like below

listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                long arg3) {
        String text= arg0.getItemAtPosition(position)

        Bundle bundle = new Bundle();

        bundle.putString("URTEXT", text);

        Intent intent = new Intent(MainActivity.this,
                        NextActivity.class);

        intent.putExtras(bundle);
        startActivity(intent);
    }
});

In Next Activity U can get that data that u passed through bundle like this

Intent intent = getIntent();
String tEXT = intent.getIntExtra("URTEXT", 0);
EditText et= (EditText)findViewById(editTextID);
et.setText(tEXT, TextView.BufferType EDITABLE);
于 2013-03-25T10:39:20.110 回答