简体   繁体   English

如何将列表视图中的单击项转移到Android中另一个活动中的editText

[英]How to transfer the clicked item in listview to editText in another activity in android

I want to get the item on list view to edit Text in another activity. 我想在列表视图中获取该项目,以在另一个活动中编辑文本。 When clicked on list view item, I want to transfer the item in another activity in edit Text. 当单击列表视图项目时,我要在编辑文本的另一个活动中转移该项目。

You have to make onItemClickListner of listview like that. 您必须像这样使listview的onItemClickListner。

listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent i = new Intent(getApplicationContext(), SecondActivity.class);
        i.putExtra("new_variable_name","value");
         startActivity(i);
        }
    });

Then in the new Activity, retrieve those values: 然后在新的活动中,检索以下值:

Bundle extras = getIntent().getExtras();

if (extras != null) { String value = extras.getString("new_variable_name"); }

And finally set Value to editText like this 最后像这样将Value设置为editText

editText.setText(value);

Hope this will help you. 希望这会帮助你。

lstView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Intent intent = new Intent(getActivity(), NewActivity.class);
            intent.putExtra("text", text want to transfer);
            startActivity(intent);
        }
    });

You can make use of SharedPreferences . 您可以使用SharedPreferences And when you pass the content of the ListView to the next activity, you can use editText.setText("Your Text") . 并且,当您将ListView的内容传递给下一个活动时,可以使用editText.setText("Your Text")

You can also pass your data through intents from which you are calling your new activity. 您还可以通过调用新活动的意图传递数据。

  1. create onClick method like this. 创建这样的onClick方法。

     ListView list = (ListView) findViewById(R.id.newsList); list.setAdapter(adapter); list.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long offset) { NewsItem item = (NewsItem) adapter.getItem(position); Intent intent = new Intent(getApplicationContext(), NewsDetailsActivity.class); intent.putExtra(KEY, item.getHeadline()); startActivity(intent); } }); 
  2. In next activity 在下一个活动中

     Intent intent = getIntent(); headline = intent.getStringExtra(KEY); 

have a look here 在这里看看

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android如何将listview项目发送到另一个活动 - android How to send listview item to another activity 如何在Android中的另一个活动中将两个edittext值传递给listview? - How to pass two edittext values to listview in another activity in android? 单击另一个活动中的EditText时,在ListView中传递数据 - Pass Data in ListView when clicked to EditText from another Activity 如何在另一个ListView上传输ListView项目? - How to transfer a ListView item on another ListView? 单击展开式列表视图中的子项时如何在另一个活动中打开列表视图 - How to open a listview in another activity when a child item in an expandable listview is clicked 如何在listview中的位置获取项目并发送到android中的另一个活动? - How to get item at position in listview and send to another activity in android? 如何更改列表视图的项目的颜色,并保持不变,直到从该列表视图的机器人单击另一个项目? - How to change color of a listview's item and keep it unchaged until another item clicked from that listview android? 如何基于从listView单击的项目设置editText对象 - How to set editText object based on item clicked from listView 单击按钮时如何将数据从editText.text传递到Xamarin Android中的另一个活动 - How to pass data from editText.text to another activity in Xamarin Android when button is clicked Android-从另一个活动将项目添加到ListView - Android - Adding item to ListView from another Activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM