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.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
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 . And when you pass the content of the ListView to the next activity, you can use editText.setText("Your Text")
.
You can also pass your data through intents from which you are calling your new activity.
create onClick
method like this.
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); } });
In next activity
Intent intent = getIntent(); headline = intent.getStringExtra(KEY);
have a look here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.