I have a ListActivity when clicked, I get the display text that was clicked on. Is there a better way, such as using a unique identifier?
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="adjustments">
<item>Item 1</item>
<item>Item 2</item>
<item>Item 3</item>
</string-array>
</resources>
I then have this as the code:
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
String[] adjustments = getResources().getStringArray(R.array.adjustments);
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, adjustments));
getListView().setTextFilterEnabled(true);
}
protected void onListItemClick(ListView l, View v, int position, long id){
super.onListItemClick(l, v, position, id);
Intent intent = new Intent();
Bundle bundle = new Bundle();
try{
bundle.putString("adjustment", l.getItemAtPosition(position).toString());
intent.putExtras(bundle);
setResult(RESULT_OK, intent);
}catch(Exception e){
setResult(RESULT_CANCELED, intent);
}
finish();
}
What I would then like to do is give each item a unique identifier instead of getting it’s text to decide what to do next. Is it at all possible? Each option will have the same methods called once clicked using reflection, so if I can call the method once instead of doing 100’s of if/else statements to check to see what was clicked that would be very helpful!
What I did was used the return text to call a class using Reflection. So if the return text was
Adjust RGBI would then remove the spaces and initiate the classAdjustRGBand run functions based on an implementation.