I have an Activity that has two clickable EditTexts and I am trying to pass value from two different ListView Activities. Every time I try to populate value to the second EditText, the value of the other EditText is cleared.
I need help in figuring out where I am wrong and a possible resolution.
This is the code for the Activity with both EditTexts
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.book_seat);
//Departure
depart = (EditText)findViewById(R.id.departure_terminal);
// This is a listener for the one way departure terminal
depart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(BookSeat.this,TerminalList.class);
startActivity(intent);
}
});
// Receiving value into activity using intent.
String TempHolder = getIntent().getStringExtra("ListViewClickedValue");
// Setting up received value into EditText.
depart.setText(TempHolder);
//Arrival
arrive = (EditText)findViewById(R.id.arrival_terminal);
// This is a listener for the one way arrival terminal
arrive.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(BookSeat.this,ArrivalTerminalList.class);
startActivity(intent);
}
});
// Receiving value into activity using intent.
String TempHolder_1 = getIntent().getStringExtra("ArrivalListViewClickedValue");
// Setting up received value into EditText.
arrive.setText(TempHolder_1);
This is the code for the first ListView
public class TerminalList extends AppCompatActivity {
ListView listView;
// Define string array.
String[] listValue = new String[] {"Anambra => Awka","Delta(South-East) => Asaba(Onitsha)","Enugu => Enugu",
"FCT Abuja => Kubwa","Imo => Owerri","Kaduna => Kaduna","Lagos => Cele/Okota","Lagos => Festac(MazaMaza)","Plateau => Jos"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.terminal_list);
listView = (ListView)findViewById(R.id.listView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, android.R.id.text1, listValue);
listView.setAdapter(adapter);
// ListView on item selected listener.
listView.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
// Getting listview click value into String variable.
String ListViewClickedValue = listValue[position].toString();
Intent intent = new Intent(TerminalList.this, BookSeat.class);
// Sending value to another activity using intent.
intent.putExtra("ListViewClickedValue", ListViewClickedValue);
startActivity(intent);
finish();
}
});
}
}
This is the code for the second ListView
public class ArrivalTerminalList extends AppCompatActivity {
ListView listView;
// Define string array.
String[] listValue = new String[] {"Anambra => Awka","Delta(South-East) => Asaba(Onitsha)","Enugu => Enugu",
"FCT Abuja => Kubwa","Imo => Owerri","Kaduna => Kaduna","Lagos => Cele/Okota","Lagos => Festac(MazaMaza)","Plateau => J-Town"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.arrival_terminal_list);
listView = (ListView)findViewById(R.id.listView2);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, android.R.id.text1, listValue);
listView.setAdapter(adapter);
// ListView on item selected listener.
listView.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
// Getting listview click value into String variable.
String ArrivalListViewClickedValue = listValue[position].toString();
Intent intent = new Intent(ArrivalTerminalList.this, BookSeat.class);
// Sending value to another activity using intent.
intent.putExtra("ArrivalListViewClickedValue", ArrivalListViewClickedValue);
startActivity(intent);
}
});
}
}