I am having trouble receiving the position or the value of a clicked ListViewItem in a SecondActivity.
My MainActivity:
public class MainActivity extends Activity {
String[] ingredients;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ingredients = getResources().getStringArray(R.array.ingredients);
final ListView ingredientList = (ListView) findViewById(R.id.ingredientList);
ArrayAdapter <String> listAdapter = new ArrayAdapter <String> (this,android.R.layout.simple_list_item_1, ingredients);
ingredientList.setAdapter(listAdapter);
ingredientList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView <?> parent, View view, int pos, long id) {
int itemPosition = pos;
String itemName = (String) ingredientList.getItemAtPosition(pos);
// THIS TOAST WORKS FINE: Toast.makeText(getApplicationContext(), "Position: " + itemPosition + " ListItem: " + itemName, Toast.LENGTH_LONG).show();
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(intent);
}
});
}
In the SecondActivity I want to display the value or the name of the clicked ListItem in a TextView like a title and I want to have another TextView and put in a text about the clicked ListViewItem.
Right now I got this:
public class SecondActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
TextView titleView = (TextView) findViewById(R.id.textView);
TextView descriptionView = (TextView) findViewById(R.id.textView2);
}
I hope you can help me! Thank you!!