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 8959265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:23:44+00:00 2026-06-15T15:23:44+00:00

I am having problems with ListView on android. I have an Activity with an

  • 0

I am having problems with ListView on android. I have an Activity with an EditText view and a button. The idea is user should enter some info in the EditText field, touch the Search button which retrieves a list from a web service that it is displayed in the same activity below the EditText and the Button. Everything fine, I got the data from Internet but items weren’t displaying. I was using the notifyDataSetChanged(). After a couple of hours with no success, I decided trying to put some items manually and it turns out that again nothing was displayed, hence I think I am doing something wrong when I am trying to set the listview and the adapter. So here is the code..

the xml of the activity activity_search.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:layout_margin="5dp">

    <EditText
        android:id="@+id/edit_search"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        android:inputType="text"
        android:hint="Enter info"
        android:ems="10" >
        <requestFocus />
    </EditText>

    <Button 
        android:id="@+id/button_search"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@android:drawable/ic_menu_search"
        android:contentDescription="Search"
        android:ems="10" />
</LinearLayout>

<ListView
    android:id="@+id/listview_items" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawSelectorOnTop="false" />

The XML of the item row.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" 
android:orientation="vertical"
android:layout_margin="5dp">

<TextView
    android:id="@+id/row_code"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/Common_TextContent" 
    android:textAppearance="@android:style/TextAppearance.Holo.Medium" />

<TextView
    android:id="@+id/row_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:text="@string/Common_TextContent"
    android:textAppearance="@android:style/TextAppearance.Holo.Small" /></LinearLayout>

the custom Adapter:

public class ItemsListAdapter extends ArrayAdapter<ItemsList> {


private int[] colors = new int[] { 0x30ffffff, 0x30808080 };

public AssetListAdapter(Context context,
        List<ItemsList> itemsList) {
    super(context, 0, itemsList);

}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = LayoutInflater.from(getContext()).inflate(R.layout.row, null);
    }

    convertView.setBackgroundColor(colors[position % colors.length]);

    TextView code = (TextView) convertView.findViewById(R.id.row_code);
    code.setText(getItem(position).getCode());

    TextView name = (TextView) convertView.findViewById(R.id.row_name);
    name.setText(getItem(position).getName());

    return convertView;
}

and the onCreate method on the Activity

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);

    _listView = (ListView) findViewById(R.id.listview_items);
    _listItems = new ArrayList<ItemsList>();

    _listItems.add(new ItemsList ("cosa1", "cosa1", "cosa1", "cosa1"));
    _listItems.add(new ItemsList ("cosa2", "cosa2", "cosa2", "cosa2"));
    _listItems.add(new ItemsList ("cosa3", "cosa3", "cosa3", "cosa3"));

    _adapter =  new ItemsListAdapter(this, _listItems);
    _listView.setAdapter(_adapter);

}

The ItemsList is just an Object with 4 strings with all the getters implemented.
When I debug in the getView method of the Adapter, the view (convertView) is created and it has the right information. It is just that is not showing those in the screen. What am I doing wrong?

Thanks…

  • 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-06-15T15:23:46+00:00Added an answer on June 15, 2026 at 3:23 pm

    Your second LinearLayout has a height of match_parent. Try wrap_content instead.

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:layout_margin="5dp">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some problems populating a ListView in Android with a rawQuery command, I'm
I am using android compatibility library, and I am having some problems with listfragments
I have a problem with back button functionality in an Activity of Android. The
I am developing one Android application having the list view of items. Those listview
I am having a problem in searching a ListView. In my activity I have
I'm trying to implement a simple android REST Client and i having some problems
I'm having problems with my first Android app. I have subclassed ListActivity, and I'm
Im having problems with displaying ONLY some elements ONLY on print page. For example
Im having problems with classpaths. I have used them before with import but I'm
I am having trouble with a scrolling ListView inside a ScrollView . I have

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.