Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Custom ListView Adapter doesn't populate
    primarykey
    data
    text
    <p>Long time stack user, first time poster. I have followed several Custom ListView Adapter tutorials and have not been able to get this one to work (I have successfully created these adapters before). I have spent way too many hours trying to get this to work!!! Can someone please have a look and hopefully find the silly mistake that I made?</p> <p>This is in MainActivity.java onCreate() to call the list</p> <pre><code>//Declaration for the list private ArrayList&lt;Consumption&gt; meals = new ArrayList&lt;Consumption&gt;(); private RAdapter rAdapter; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_meal); //This is the first of two listviews on the activity adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, listItems); ListView listView = (ListView) findViewById(R.id.listView1); listView.setAdapter(adapter); //This is the listview I am having problems with ListView listView2 = (ListView) findViewById(R.id.resultList); rAdapter = new RAdapter(this,meals); listView2.setAdapter(rAdapter); } </code></pre> <p>I have triple checked that meals has data, it does.</p> <p>This is the RAdapter.java (The Custom Adapter) code:</p> <pre><code>public class RAdapter extends ArrayAdapter&lt;Consumption&gt;{ static class holder{ TextView rName; EditText quan; ImageButton delete; } private ArrayList&lt;Consumption&gt; meals; private final Context context; public RAdapter(Context context) { super(context, R.layout.result_row); this.context = context; } public RAdapter(Context context, ArrayList&lt;Consumption&gt; meals) { super(context, R.layout.result_row); this.context = context; this.meals = meals; } public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; holder h = null; if (v == null) { LayoutInflater inflater = ((Activity)context).getLayoutInflater(); v = inflater.inflate(R.layout.result_row, parent, false); h = new holder(); h.rName = (TextView) v.findViewById(R.id.resultName); h.quan = (EditText) v.findViewById(R.id.resultGrams); h.delete = (ImageButton) v.findViewById(R.id.resultDelete); v.setTag(h); }else{ h = (holder) v.getTag(); } Consumption i = meals.get(position); h.rName.setText(i.getShortName()); h.quan.setText(i.getQuantity()); return v; } } </code></pre> <p>Here is result_row.xml (The specific row to populate):</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="match_parent" android:layout_height="wrap_content" &gt; &lt;ImageButton android:id="@+id/resultDelete" android:layout_marginLeft="10dp" android:layout_width="35dp" android:layout_height="35dp" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:src="@android:drawable/ic_notification_clear_all" android:contentDescription="@string/meal_remove" /&gt; &lt;TextView android:id="@+id/resultName" android:layout_marginLeft="10dp" android:layout_width="150dp" android:layout_height="40sp" android:layout_centerVertical="true" android:layout_toRightOf="@+id/resultDelete" /&gt; &lt;EditText android:id="@+id/resultQuantity" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_width="50dp" android:layout_height="40sp" android:inputType="numberDecimal" android:layout_toRightOf="@+id/resultName" android:layout_centerVertical="true" /&gt; &lt;TextView android:id="@+id/resultGrams" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@+id/resultQuantity" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:text="@string/grams" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Here is activity_meal.xml (which has the listview "resultList" in it):</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/semislantedbacktransparent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MealActivity" &gt; &lt;LinearLayout android:id="@+id/linearLayout1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:orientation="horizontal" &gt; &lt;ImageButton android:id="@+id/translateButton" android:layout_width="100dp" android:layout_height="65dp" android:background="@drawable/addtorecipe" android:contentDescription="@string/dummy_button" android:text="@string/button_add_recipe" /&gt; &lt;/LinearLayout&gt; &lt;SearchView android:id="@+id/searchView1" android:layout_width="fill_parent" android:layout_height="50dp" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:background="@drawable/search" android:focusable="true" android:iconifiedByDefault="false" android:onClick="enterTomInput" android:queryHint="Search for food items" android:showAsAction="always" android:textColor="#000000" &gt; &lt;/SearchView&gt; &lt;ListView android:id="@+id/listView1" android:layout_width="match_parent" android:layout_height="150dp" android:layout_alignLeft="@+id/searchView1" android:layout_below="@+id/searchView1" android:cacheColorHint="@color/black_overlay" &gt; &lt;/ListView&gt; &lt;ListView android:id="@+id/resultList" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_above="@+id/linearLayout1" android:layout_below="@+id/listView1" /&gt; &lt;ImageButton android:id="@+id/completeButton" android:layout_width="100dp" android:layout_height="65dp" android:layout_alignRight="@+id/resultList" android:layout_alignTop="@+id/linearLayout1" android:background="@drawable/completemeal" android:contentDescription="@string/dummy_button" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>I can post a logcat, but there is no error message to report. I have tried putting System prints everywhere, but cannot figure the problem out.</p> <p>Any help would be much appreciated!!</p>
    singulars
    1. This table or related slice is empty.
    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.
    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