I have a simple question, I know you can use:
setListAdapter(new ArrayAdapter<String> (getActivity(),
R.layout.your_layout,
R.id.your_text,
stringArray));
inside a ListFragment on your onActivityCreated() method. This works well for me so far, but only covers one item. For instance, say if in the the layout, I had two TextViews: sms_text, and sms_timestamp; both to be filled by smsTextArray [] and smsTimeStampArray [] respectively. How would that call be? I tried:
setListAdapter(new ArrayAdapter<String> (getActivity(),
R.layout.tweet_list_item,
R.id.sms_text,
smsTextArray,
R.id.sms_timestamp,
smsTimeStampArray,
));
That did not work 🙁
I also tried calling setListAdapter() twice in the same onActivityCreated(), but although that worked, it only displayed the second call of setListAdapter() in the list items.
I also tried creating my own Adapter but I kind of got lost in that mess. Can you guys point me in the right direction? I do not need the exact code, just a link to a library I could read, or perhaps it is a simple as just a code call. Who knows, maybe I am just using the wrong parameters, any ideas?
You can’t use a simple
ArrayAdapterand display more than one piece of data. An adapter maps one element in the list to one element in the listView. To have data come from two different pieces you need to either create your own adapter (simpler than it sounds). Or alternatively you can use a list of Maps in aSimpleAdapter(see this for an example).Personally, I’d recommend going for the custom Adapter. You’re going to have to code one eventually, and there’s no time like the present. Plus, you’re code will be more readable and obvious.