I have the following diagram for this issue I am facing; enter image description here
Here is a sample of the ArrayList in my code;
[{name0=Adventurousness, value0=46}, {value1=98, name1=Artistic interests}, {name2=Emotionality, value2=70}, {value3=54, name3=Imagination}, {value4=99, name4=Intellect}, {value5=98, name5=Authority-challenging}, {name0=Achievement striving, value0=62}, {value1=98, name1=Cautiousness}, {name2=Dutifulness, value2=69}, {value3=75, name3=Orderliness}, {value4=44, name4=Self-discipline}, {value5=65, name5=Self-efficacy}, {name0=Activity level, value0=69}, {value1=75, name1=Assertiveness}, {name2=Cheerfulness, value2=0}, {value3=6, name3=Excitement-seeking}, {value4=7, name4=Outgoing}, {value5=0, name5=Gregariousness}, {name0=Altruism, value0=84}, {value1=86, name1=Cooperation}, {name2=Modesty, value2=61}, {value3=81, name3=Uncompromising}, {value4=99, name4=Sympathy}, {value5=54, name5=Trust}, {name0=Fiery, value0=5}, {value1=19, name1=Prone to worry}, {name2=Melancholy, value2=76}, {value3=46, name3=Immoderation}, {value4=72, name4=Self-consciousness}, {value5=18, name5=Susceptible to stress}]
You can imagine another similar ArrayList that contains (name0
,value0
) values.
I don't know how to achieve this, I tried something like this but didn't work; These are the IDs inside the ListView
where I want the values in.
sample1Adapter = new SimpleAdapter(getApplicationContext(), sample1List2,
R.layout.samplecontent, new String[]{ "name0", "value0",
"name1", "value1", "name2", "value2",
"name3", "value3", "name4", "value4", "name5", "value5"},
new int[]{R.id.name2, R.id.value2, R.id.name3, R.id.value3,
R.id.name4, R.id.value4, R.id.name5, R.id.value5,
R.id.name6, R.id.value6, R.id.name7, R.id.value7});
listview.setVerticalScrollBarEnabled(true);
listview.setAdapter(sample1Adapter);
Thank you.
-
1Please take a look in to this post , may help you stackoverflow.com/questions/6383330/…AnasAbubacker– AnasAbubacker2017年12月21日 06:06:36 +00:00Commented Dec 21, 2017 at 6:06
-
I already saw that post. The change is in that question, I want all the data values ("first_data1" etc), under the "firstname1_data1" value.Zac– Zac2017年12月21日 06:28:07 +00:00Commented Dec 21, 2017 at 6:28
3 Answers 3
It looks like you want to display 4 key value pairs per row. Create an object that has those key value pairs, then tie your adapter to a List of those objects. Suppose the key value pairs represented attributes of a Magazine:
class Magazine implements Parcelable
String publisher;
String title;
int numCopiesAvailable;
int numCopiesSold;
String getPublisher()
Pass the List of type Magazine to your custom adapter and inside it render each element. One row with the 4 attributes are displayed per row
3 Comments
Solution 1:
Instead of SimpleAdapter
use ArrayAdapter
where pass your ArrayList<HashMap>
object
Solution2:
Create your custom adapter and its constructor pass your ArrayList<HashMap>
object and handle data inside it to load into your ListView
1 Comment
Support there are 3 ArrayList<HashMap>
than put them to into one finalList.
Take another
ArrayList<HashMap> finalList = new HashMap();
you can take a loop an add all to this final List
finalList.put("0",haspMapList1);
finalList.put("1",haspMapList2);
Than pass this list in your CustomListAdapter.