I have custom tableview with a text, a subtext and an image. I've defined a class called Lines and an XML-file for the layout of each line. It works perfect.
But: If I increase or decrease the number of lines in my XML-arrays, ( 4 or 2) I have to change the so开发者_C百科urce code. Add or remove some lines of code. How can I solve that problem?
Thanks a lot for your help.
Regards, Joachim
String[] a_titles = getResources().getStringArray(R.array.titles);
String[] a_subtitles = getResources().getStringArray(R.array.subtitles1);
String[] a_images = getResources().getStringArray(R.array.images);
m_lines = new ArrayList<Lines>();
Lines o1 = new Lines();
o1.setTitle(a_titles[0]);
o1.setSubTitle(a_subtitles[0]);
o1.setImage(a_images[0]);
m_lines.add(o1);
Lines o2 = new Lines();
o2.setTitle(a_titles[1]);
o2.setSubTitle(a_subtitles[1]);
o2.setImage(a_images[1]);
m_lines.add(o2);
Lines o3 = new Lines();
o3.setTitle(a_titles[2]);
o3.setSubTitle(a_subtitles[2]);
o3.setImage(a_images[2]);
m_lines.add(o3);
If you want to have a dynamic number of rows you really should be using a ListView
with a custom Adapter
. There are a lot of really good examples of how to do this online. Including in the samples that come with the SDK.
精彩评论