Note that there are some explanatory texts on larger screens.

plurals
  1. POmultiple listview inside listfragment
    text
    copied!<p>please bare with me as i am still learning android and java.</p> <p>i have been working on trying to implement two listviews inside a list fragment, i have stated two list views in my xml and tried to set two seperate sets of data in the java file but the list view data intended for the first lisview is overwritten by the second.</p> <p>how would i be able to point it to the correct listviews using the code below?</p> <p>java for fragment where list should go:</p> <pre><code>package com.owais.shopsellswap; import java.util.ArrayList; import java.util.HashMap; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.SimpleAdapter; public class Fragment_My_Profile extends ListFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View myProfileView = inflater.inflate(R.layout.fragment_my_profile, container, false); return myProfileView; } // Store Arralist as hashmaps for the listview ArrayList&lt;HashMap&lt;String,String&gt;&gt; list = new ArrayList&lt;HashMap&lt;String,String&gt;&gt;(); ArrayList&lt;HashMap&lt;String,String&gt;&gt; list2 = new ArrayList&lt;HashMap&lt;String,String&gt;&gt;(); // SimpleAdapter (listViewAdapter) links the array to the listview private SimpleAdapter listViewAdapter; private SimpleAdapter listViewAdapter2; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //HashMap links each line of data to the correct TextView HashMap&lt;String,String&gt; item; for(int i=0;i&lt;userInfo.length;i++){ item = new HashMap&lt;String,String&gt;(); item.put( "line1", userInfo[i][0]); item.put( "line2", userInfo[i][1]); list.add( item ); } HashMap&lt;String,String&gt; item2; for(int i=0;i&lt;ListingsArray.length;i++){ item2 = new HashMap&lt;String,String&gt;(); item2.put( "line1", ListingsArray[i][0]); item2.put( "line2", ListingsArray[i][1]); item2.put( "line3", ListingsArray[i][2]); list2.add( item2 ); } listViewAdapter = new SimpleAdapter(getActivity(), list, R.layout.listview_layout_1, new String[] { "line1","line2" }, new int[] {R.id.line_a, R.id.line_b}); listViewAdapter2 = new SimpleAdapter(getActivity(), list2, R.layout.listview_layout_3, new String[] { "line1","line2", "line3" }, new int[] {R.id.line_a1, R.id.line_b1, R.id.line_c1}); setListAdapter(listViewAdapter); setListAdapter(listViewAdapter2); } private String[][] userInfo = {{"User","Dummy"}, {"Email Address","Dummy@dummymail.com"}, {"User Type","Staff"}, {"Contact Number","07111111111"}}; private String[][] ListingsArray = {{"audi a3","brand new audi a3 with alloywheels, cd player", "£11000"}, {"HTC One x","brand new android smartphone", "£450"}, {"Acer Laptop","Acer Laptop with windows 7", "£300"}, {"Sunglass","Oakley Sunglasses in great condition", "£100"}}; } </code></pre> <p>xml for the fragment:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;TextView android:id="@+id/textView2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/lightgrey" android:text="@string/userInfoHeader" android:textSize="15sp" android:textStyle="bold" /&gt; &lt;ListView android:id="@+id/android:list" android:layout_width="fill_parent" android:layout_height="184dp" android:layout_alignParentLeft="true" android:layout_below="@+id/textView2" &gt; &lt;/ListView&gt; &lt;TextView android:id="@+id/textView3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/android:list" android:background="@color/lightgrey" android:text="@string/listingsHeader" android:textSize="15sp" android:textStyle="bold" /&gt; &lt;ListView android:id="@+id/android:list2" android:layout_width="fill_parent" android:layout_height="184dp" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" &gt; &lt;/ListView&gt; &lt;/RelativeLayout&gt; </code></pre> <p>the list view also uses a custom layout for each list , if the code is needed for that too , please let me know and ill upload it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload