Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3601888
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:40:37+00:00 2026-05-18T20:40:37+00:00

I have a very basic ListView in android and had set a very basic

  • 0

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();

Here is my code:
XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
  <TextView android:text="@string/app_name"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  ></TextView>
  <ListView android:id="@+id/selectView"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content">
    </ListView>
</RelativeLayout>

The Activity 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();
    }
}

And the Adapter 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;
    }

}

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:40:38+00:00Added an answer on May 18, 2026 at 8:40 pm

    A few things I can think of.

    First, Your RelativeLayout has no relative positioning information. I would assume you meant to put this in a LinearLayout with orientation set to vertical from what you describe. My guess is that the list is not actually being drawn since it isn’t even anchored to anything in the current RelativeLayout. If you stick with the RelativeLayout, make sure to put an id on the app_name TextView and position the ListView under it via layout_below.

    LinearLayout Solution

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content">
      <TextView android:text="@string/app_name"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      ></TextView>
      <ListView android:id="@+id/selectView"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content">
        </ListView>
    </LinearLayout>
    

    RelativeLayout Solution:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content">
      <TextView
      android:id="@+id/app_name_text" 
      android:text="@string/app_name"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentTop="true"
      ></TextView>
      <ListView android:id="@+id/selectView"
        android:layout_below="@id/app_name_text"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content">
        </ListView>
    </RelativeLayout>
    

    Next, your getView() returns the same textView for all 3 indexes. It’s not a problem to display the same view over multiple indexes however with a list size of three, I am betting that the screen can display all three at the same time. And since a View can’t be in more than one position at a time, I actually would expect this to fail so I doubt it is even getting to this code yet. Try creating a new TextView for each getView(). Also your MockTextView doesn’t have layout params of it’s own. So laying it out within a listView cell might not be happening either. So you can give it params of type AbsListView.LayoutParams(WRAP_CONTENT, WRAP_CONTENT). Again though I would expect this to error if it got to the original code.

    getView() tidy up:

     @Override
        public View getView(int position, View convertView, ViewGroup parent) {
           if(convertView == null) {
              TextView textView = new TextView(parent.getContext());
              textView.setText("Position is:"+position);
              textView.setBackgroundColor(Color.CYAN);
              textView.setLayoutParams(new AbsListView.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
              convertView = textView;
            }
            return mMockTextView;
        }
    

    And lastly the wrap_content height of your list can sometimes be problematic. I am not aware of all the scenarios. If you end up changing to a LinearLayout try setting your layout_height of the list view to 0 and then set the layout_weight=1. This forces the linear layout to inflate it into more space.

    LinearLayout Weight Solution:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content">
      <TextView android:text="@string/app_name"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      ></TextView>
      <ListView android:id="@+id/selectView"
        android:layout_weight="1"
        android:layout_height="0dp"
        android:layout_width="wrap_content">
        </ListView>
    </LinearLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very basic email submission form in my ASP.NET MVC 3 app.
I have a very basic question. I would like to know if here is
I have a very basic iphone app where the following steps occur. App Delegate
I'm looking for some sort of very basic privilege escalation example that I can
I realise this is very basic but i need a quick way of referencing
I'm learning Java and I wanted to create a very basic Calculator to calculate
I've encountered an architectural issue with my application. I've rolled my own (very basic)
I'm trying to implement search functionality in my app, which is very basic at
I have seen many tutorials, but they're so confusing, and to do what I
I'm working on a solo project, using the aforementioned technologies. The aim is to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.