I’ve been trying to set and EdiText on my activity when a ListView is called and an item is selected but everything I have tried doesn’t work. How I have it setup is Main.class button opens ListView.class, iterm is slected on ListView and the sets EditText on Main.class with that value.
Here is my code:
Main.class:
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch(arg0.getId()){
case R.id.bSetListItem:
Intent i = new Intent(getBaseContext(),
PhotoDialog.class);
startActivityForResult(i, GET_ITEM);
break;
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode) {
case PICK_ITEM:
// handle the contact result
Bundle extras = data.getExtras();
String val = extras.getString("item");
itemName.setText(val);
break;
}
}
ListView.class:
public void onListItemClick(ListView parent, View v, int position,long id) {
Intent data = new Intent(this,Main.class);
data.putExtra("key","SELECTED ITEM");
setResult(RESULT_OK, Intent data);
}
you didn’t finish your list activity when you start your activity for result you must finish your activity by calling finish() method
another thing is whatever key you have to set into put time same that key was used for getting time
Edit:
you have set the “this” and “Main.class” into the intent, when you start activity for result and set the data then no need to set the context object and class name into the Intent constructor. The Intent() constructor was empty call and just put the data you want to set as result