Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Multi-Line Listview in fragment
    primarykey
    data
    text
    <p><em>Please bare with me if I do not understand your answers , I am still learning Java and new to android.</em> </p> <p>I have an app that uses a tab layout using fragments, in one of the fragments I would like to have a two/multi-line List View, I have been following this <a href="http://tekeye.biz/2012/two-line-lists-in-android" rel="nofollow">tutorial</a> which shows it for a <code>ListActivity</code>. I have copied the code into my fragment and cannot seem to get it to work. all of my code for the layout of the fragment and the two lines is the same as code in the link above, with the exception of the Java class for the fragment I want to show the list in. </p> <p>the code for the fragment is as follows:</p> <pre><code>package com.example.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; } //ArrayList holds the data (as HashMaps) to load into the ListView ArrayList&lt;HashMap&lt;String,String&gt;&gt; list = new ArrayList&lt;HashMap&lt;String,String&gt;&gt;(); //SimpleAdapter does the work to load the data in to the ListView private SimpleAdapter sa; @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;StatesAndCapitals.length;i++){ item = new HashMap&lt;String,String&gt;(); item.put( "line1", StatesAndCapitals[i][0]); item.put( "line2", StatesAndCapitals[i][3]); list.add( item ); } sa = new SimpleAdapter(Fragment_My_Profile.this, list, R.layout.my_two_lines, new String[] { "line1","line2" }, new int[] {R.id.line_a, R.id.line_b}); setListAdapter(sa); } private String[][] StatesAndCapitals = {{"Alabama","Montgomery"}, {"Alaska","Juneau"}, {"Arizona","Phoenix"}, {"Arkansas","Little Rock"}, {"California","Sacramento"}}; </code></pre> <p>The part that is giving me errors is </p> <pre><code> sa = new SimpleAdapter(Fragment_My_Profile.this, list, R.layout.my_two_lines, new String[] { "line1","line2" }, new int[] {R.id.line_a, R.id.line_b}); setListAdapter(sa); </code></pre> <p>the specific error is: </p> <pre><code>The constructor SimpleAdapter(Fragment_My_Profile, ArrayList&lt;HashMap&lt;String,String&gt;&gt;, int, String[], int[]) is undefined </code></pre> <p>what's weird is when I change <code>ListFragment</code> to <code>ListActivity</code> the error is no longer there</p> <p>Why it isn't working and how I can fix it? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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