传递数据从列表视图到EDITTEXT [英] Pass Data from Listview to Edittext

查看:97
本文介绍了传递数据从列表视图到EDITTEXT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CustomListView中,我有两个文本框和两个图像。我需要文本数据传递到另一个活动的EDITTEXT。

I have a CustomListView in which I have two textbox and two images. I need to pass textbox data to the Edittext of another activity.

感谢

推荐答案

首先,你需要获得一个参考的TextView 自定义适配器
之后,将它保存在文本字符串,并使用该值传递给其他活动意图

First you need to get a reference to the TextView of the Custom Adapter. After that save it's text in a String and pass that value to the other Activity using an Intent.

draft_list.setOnItemClickListener(new OnItemClickListener()
    {

        @Override
        public void onItemClick(AdapterView<?> arg0, final View itemView, int arg2,long arg3)
        {
            //Reference both text views and get their current text.

            TextView textViewOne = (TextView)itemView.findViewById(R.id.your_textViewOne_ID);
            String contentOne = textViewOne.getText().toString();

            TextView textViewTwo = (TextView)itemView.findViewById(R.id.your_textViewTwo_ID);
            String contentTwo = textViewTwo.getText().toString();

            //Pass the values to the other activity.

            Intent intent = new Intent(currentActivity.this, newActivity.class);
            intent.putExtra("contentOne", contentOne);
            intent.putExtra("contentTwo", contentTwo);
            startActivity(intent);
         }
 });

在您的接收活动,然后获取数据这样:

In your receiving activity then get the data as such:

//In your other activity, receive the intent and store the Extra values.

Intent intent = getIntent();
String receivedContentOne = intent.getStringExtra("contentOne");
String receivedContentTwo = intent.getStringExtra("contentTwo");

// Set EditText text to the values passed from the intent.

EditText editTextOne = (EditText)findViewById(R.id.your_editTextOne_ID);
editTextOne.setText(String.valueOf(receivedContentOne));

EditText editTextTwo = (EditText)findViewById(R.id.your_editTextTwo_ID);
editTextTwo.setText(String.valueOf(receivedContentTwo));

这篇关于传递数据从列表视图到EDITTEXT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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