I am new to java and android. I have a 2 dimensional array that contains a number and a name like this:
String[][] array = new String[2][2];
array[0][0] = "1";
array[0][1] = "Mickey"";
array[1][0] = "2";
array[1][1] = "Mouse";
The array is changing by incoming data via bluetooth - so I can not "hardcode" it. I want to make a ListView which shows just the names but if you click on it, it will give the number (matching to this name) to the to a new activity.
So far i have this which caused me almost more than a day:
mLstModes = (ListView) findViewById(R.id.LstModes);
ArrayList<String> arrayList = new ArrayList<String>();
//here I want to "add" also the number...
arrayList.add(array[0][1]);
arrayList.add(array[1][1]);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, arrayList);
mLstModes.setAdapter(arrayAdapter);
mLstModes.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int pos, long id)
{
Intent intent = new Intent();
intent.setClassName(getPackageName(), getPackageName()+ ".NextActivity");
intent.putExtra("selected", "I WANT THE NUMBER HERE");
startActivity(intent);
}
});
The problem is, that I dont know how to add also the number to the arrayList, so that I can easily let the onItemClick method hand over the number of the name.
Sorry if the question is noobish but I hope someone can help me out. Thanks!