I have ListView activity class:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] naziviMolitvi = getResources().getStringArray(R.array.nazivi_molitvi);
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, naziviMolitvi));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Intent intent = new Intent(getApplicationContext(), Molitva.class);
//Bundle bundle = new Bundle();
//bundle.putInt("pozicija", position);
//intent.putExtras(bundle);
startActivity(intent);
// Toast.makeText(getApplicationContext(),
// ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
}
});
}
I have list items stored in strings.xml file in string-array:
<string-array name="nazivi_molitvi">
<item>Дневне молитве</item>
<item>Символ вере</item>
<item>Псалм 50</item>
<item>Свакодневна молитва</item>
<item>Молитва Пресветој Богородици у невољи и потиштености</item>
<item>Поздрав Богородици</item>
<item>Јутарња молитва</item>
<item>Вечерња молитва</item>
<item>Молитва Анђелу Чувару</item>
<item>Молитва пред Свето Причешће</item>
<item>Молитва после Светог Причешћа</item>
<item>Молитва за међусобни мир</item>
<item>Молитва пре учења</item>
<item>Молитва после учења</item>
<item>Молитва пре доручка</item>
<item>Молитва после доручка</item>
<item>Молитва пре ручка</item>
<item>Молитва после ручка</item>
<item>Молитва пре вечере</item>
<item>Молитва после вечере</item>
<item>Десет Божијих Заповести</item>
<item>Две највеће Христове Заповести</item>
<item>Химна Светом Сави</item>
<item>Српска Химна "Боже правде"</item>
</string-array>
Now when user clicks on single item I want to show expanded text for that view. Where to store this text? If I store text in string array then I don’t know how to reference to single item in it.
Maybe for every item to make string with certain name and when user clicks item in list view to have switch statement, like this:
public class Molitva extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.molitva);
Bundle bundle = this.getIntent().getExtras();
int pozicija = bundle.getInt("pozicija");
TextView tv = (TextView) this.findViewById(R.id.textView1);
tv.append(" - " + getPrayerText(pozicija));
}
}
Is that good practice for selecting list item and what you suggest me? How to do this?
I would assume that the list of expanded text is the same size as your list, and the indices are equal and corresponding.
You can also store the expanded text list on arrays.xml and get hold of them as you did with your non-expanded list – using
getResources().getStringArray. You can use the position you passed in the bundle to get the item in your expanded text list.// to get the item at position
pozicija