I am building an android application which has a listview and when the user clicks on the listview item then a new activity is started. I want to pass some data to the new activity. I have two local variables titles and descriptions which I want to use inside that method. Compiler is throwing an error saying that descriptions should be a final type to use in there. Because the descriptions array is generated dynamically I cant make it final.
Is there something that I am missing or is there any other way to work with this?
String[] titles = someClass.getTitles();
String[] descriptions = someClass.getDescriptions();
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, titles));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
Intent i = new Intent(TitleView.this, DetailView.class);
i.putExtra("title", ((TextView) view).getText());
i.putExtra("description", descriptions[new Long(id).intValue()]);
startActivity(i);
}
});
Thanks
If you specify the
descriptionsasfinal, it doesnt mean it can not be built dynamically.It means that once
descriptionsis loaded with what is returned fromsomeClass.getDescriptions();, it can not be reassigned to something else (and if it is the case, it will throw an error at compile time).