从设置列表视图到另一个活动的EditText文本单击某一行的时候? [英] Setting text from Listview to EditText of Another Activity when a row is clicked?

查看:198
本文介绍了从设置列表视图到另一个活动的EditText文本单击某一行的时候?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表视图,我要到ListView的文字传递给另一个Activity.Canü帮助?

I have a listview, I want to pass the Text of the listview to edittext of the another Activity.Can u help?

    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);
}

当我点击第一行,接下来的活动将展示雨中担任的EditText。

When I click the first row,the next activity will show "Cloudy" as in the edittext.

推荐答案

您可以为UR列表视图创建一个列表视图onItemClickListener,当用户点击列表项/行u能得到该行文本和u可以将它传递给下一个乌尔说要打电话和活动通过捆绑和意图像下面乌尔传递数据

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);
        }
    });

在接下来的活动u能得到这些数据,美通过这样的包通过

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);

这篇关于从设置列表视图到另一个活动的EditText文本单击某一行的时候?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆