In my application Two edit boxes are there,when clicking appropriate Editbox it will show An listview(which is another intent.From that user have to select 1 input,i am assigning these value to the textbox.Myproblem is when i set value for 1 editbox and clicking another textbox to get values the 1st textbox value is not there.
My Code is:
Screen with edittext box:
public void onCreate(Bundle savedInstanceState)
{
final String fromunit=getIntent().getStringExtra("Fromunit");
final String tounit=getIntent().getStringExtra("Tounit");
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText medit=(EditText)findViewById(R.id.editText1);
EditText meditfrom=(EditText)findViewById(R.id.editText2);
Button b1=(Button)findViewById(R.id.button1);
EditText meditto=(EditText)findViewById(R.id.editText3);
meditfrom.setText(fromunit);
meditto.setText(tounit);
meditfrom.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent arg1)
Intent FromIntent= new Intent(v.getContext(),Fromlist.class);
startActivity(FromIntent);
return false;
}
});
meditto.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent arg1)
{
// TODO Auto-generated method stub
Intent ToIntent= new Intent(v.getContext(),Tolist.class);
startActivity(ToIntent);
return false;
}
});
The ListView Screen:
FOR 1st editbox:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this, R.layout.fromunit, FROMUNIT));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
// Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
// Toast.LENGTH_SHORT).show();
Intent prev=new Intent(view.getContext(),ServiceExampleActivity.class);
prev.putExtra("Fromunit",((TextView) view).getText());
startActivity(prev);
}
});
}
For 2nd edittextbox:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this, R.layout.fromunit, TOUNIT));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
// Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
// Toast.LENGTH_SHORT).show();
Intent prev=new Intent(view.getContext(),ServiceExampleActivity.class);
prev.putExtra("Tounit",((TextView) view).getText());
startActivity(prev);
}
});
}
try
You should use
startActivityForresult()
method to start another Activityeg: In FirstActivity
In secondActivity if you want to send back data
if you don't want to return data
Now in your FirstActivity class write following code for
onActivityResult()
method