1

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.

Abdur Rehman
3,3035 gold badges35 silver badges50 bronze badges
asked Dec 21, 2017 at 6:02
2
  • 1
    Please take a look in to this post , may help you stackoverflow.com/questions/6383330/… Commented 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. Commented Dec 21, 2017 at 6:28

3 Answers 3

0

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

answered Dec 21, 2017 at 6:13

3 Comments

Can you answer my question please. This makes no sense.
It answers your question. If you want to show 4 key value pairs per row, create a model that represents it, then render it through a recyclerview. A recyclerview needs an adapter, so pass a List of that model to the adapter. You are making an easy problem difficult
The question is how. I have all the variables, data in the question. If you can't answer the question properly, please refrain from writing answers.
0

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

LuFFy
9,36310 gold badges43 silver badges59 bronze badges
answered Dec 21, 2017 at 6:16

1 Comment

0

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.

AskNilesh
69.9k16 gold badges134 silver badges170 bronze badges
answered Dec 21, 2017 at 6:24

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.