Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is my ListView not showing anything?
    text
    copied!<p>I have a very basic ListView in android and had set a very basic adapter. My problem is that the list view does not show anything, regardless of the adapter and the notifyDataSetChanged(); </p> <p>Here is my code: XML:</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="wrap_content" android:layout_height="wrap_content"&gt; &lt;TextView android:text="@string/app_name" android:layout_width="wrap_content" android:layout_height="wrap_content" &gt;&lt;/TextView&gt; &lt;ListView android:id="@+id/selectView" android:layout_height="wrap_content" android:layout_width="wrap_content"&gt; &lt;/ListView&gt; &lt;/RelativeLayout&gt; </code></pre> <p>The Activity code:</p> <pre><code>import android.app.Activity; import android.os.Bundle; import android.widget.ListView; import com.androidcourse.phonemapper.R; import com.androidcourse.phonemapper.model.SelectViewAdapter; public class SelectActivity extends Activity { private ListView mListView; private SelectViewAdapter mAdapter; @Override public void onCreate(Bundle savedState) { super.onCreate(savedState); setContentView(R.layout.select_activity); initializeListView(); } private void initializeListView() { mListView = (ListView) findViewById(R.id.selectView); mAdapter = new SelectViewAdapter(this); mListView.setAdapter(mAdapter); mAdapter.notifyDataSetChanged(); } @Override public void onResume() { super.onResume(); } } </code></pre> <p>And the Adapter code:</p> <pre><code>import android.content.Context; import android.graphics.Color; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; public class SelectViewAdapter extends BaseAdapter { private Context mContext; private TextView mMockTextView; public SelectViewAdapter(Context cnt) { mContext = cnt; mMockTextView = new TextView(mContext); mMockTextView.setText("Test text"); mMockTextView.setBackgroundColor(Color.CYAN); } @Override public int getCount() { return 3; } @Override public Object getItem(int position) { return mMockTextView; } @Override public long getItemId(int position) { return 3; } @Override public View getView(int position, View convertView, ViewGroup parent) { return mMockTextView; } } </code></pre> <p>The problem is that nothing is shown on the screen. A black screen (and the first text view from the XML) is all I get. I cannot see the mockTextView and its text. Apparently I am doing something quite wrong, but I cant figure out what.</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