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

  • Home
  • SEARCH
  • 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 6216039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:09:43+00:00 2026-05-24T07:09:43+00:00

I extended ArrayAdapter to support an image rendered aside two TextViews. The layout itself

  • 0

I extended ArrayAdapter to support an image rendered aside two TextViews.

The layout itself is rendered correct with a generic ArrayAdapter (which only defines the text of one TextView).

https://i.stack.imgur.com/nRSKQ.jpg

When using the custom adapter (which overwrites ArrayAdapter.getView() to set icon and texts), the rendering is missing the “Hello World” – R.id.item_title – text.

https://i.stack.imgur.com/FSc5Z.jpg

hierarchyviewer: item_title – Layout/getHeight() = 0, but content “Hello World” is defined as text.

When setting R.id.item_subtitle to View.GONE, R.id.item_title will be rendered (as expected).

Do you know for what reason R.id.item_title has a height of zero, so no text is rendered/viewable? Is their something missing at SimpleImageItemAdapter.getView()?

developer.android.com/reference/android/widget/ArrayAdapter.html

To use something other than TextViews for the array display, for
instance, ImageViews, or to have some of data besides toString()
results fill the views, override getView(int, View, ViewGroup) to
return the type of view you want.


Source

tasks_dialog.xml – contains ListView

<?xml version="1.0" encoding="utf-8"?>
<ListView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tasks_dialog"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
/>

tasks_dialog_item.xml – items rendered by ListView, based on developer.android.com/resources/articles/layout-tricks-efficiency.html

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:padding="6dip">

    <ImageView
        android:id="@+id/item_icon"

        android:layout_width="wrap_content"
        android:layout_height="fill_parent"

        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_marginRight="6dip"

        android:src="@drawable/icon" />

    <TextView  
        android:id="@+id/item_subtitle"

        android:layout_width="fill_parent"
        android:layout_height="wrap_content"

        android:layout_toRightOf="@id/item_icon"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"

        android:text="Simple application that shows how to use RelativeLayout"
        android:ellipsize="marquee"
        android:singleLine="true"
 />

    <TextView
        android:id="@+id/item_title"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"

        android:layout_toRightOf="@id/item_icon"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_above="@id/item_subtitle"
        android:layout_alignWithParentIfMissing="true"

        android:gravity="center_vertical"
        android:text="My Application" android:minHeight="6dp"/>

</RelativeLayout>

TestActivity.java

public class TestActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tasks_dialog);

        ListAdapter adapter;

        // ArrayAdapter - works perfect. See screenshot #1
        {
            ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.tasks_dialog_item, R.id.item_title);
            arrayAdapter.add("Hello World");
            arrayAdapter.add("Lorem Ipsum");

            adapter = arrayAdapter;
        }

        // Custom adapter - unexpected result: missing TextView `item_title`. See screenshot #2
        {
            ContentValues[] customItems = new ContentValues[2];

            customItems[0] = new ContentValues(); // do not overwrite item - use default texts for testing
            customItems[1] = new ContentValues(); // do not overwrite item - use default texts for testing

            adapter = new SimpleImageItemAdapter(this, R.layout.tasks_dialog_item, customItems);
        }

        // render ListView with adapter or customAdapter
        ListView menuList = (ListView) findViewById(R.id.tasks_dialog);
        menuList.setAdapter(adapter);
    }
}

SimpleImageItemAdapter.java

/**
 * Simple adapter renders an icon and up to two text views based on ContentValue encoded data.
 * 
 * Usage/variables:
 * 
 * > ContentValues.put("title", "Hello World");
 * > ContentValues.put("subtitle", "»Hello World« is a dummy text");
 * > ContentValues.put("icon", R.drawable.fancyIcon);
 */
public class SimpleImageItemAdapter extends ArrayAdapter<ContentValues> {
    protected ContentValues[] mItems;


    public SimpleImageItemAdapter (Context context, int textViewResourceId, ContentValues[] items) {
        super(context, textViewResourceId, items);

        mItems = items;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // load layout
        if (convertView == null) {
            LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = layoutInflater.inflate(R.layout.tasks_dialog_item, null);
        }

        ContentValues item = mItems[position];

        // render elements
        if (item != null) {
            if (item.getAsString("title") != null) {
                TextView titleView = (TextView) convertView.findViewById(R.id.item_title);
                titleView.setText((String) item.get("title"));
            }

            if (item.getAsString("subtitle")  != null) {
                TextView subTitleView = (TextView) convertView.findViewById(R.id.item_subtitle);
                subTitleView.setText((String) item.get("subtitle"));
            }

            if (item.getAsInteger("icon") != null) {
                ImageView imageView = (ImageView) convertView.findViewById(R.id.item_icon);
                imageView.setImageDrawable(convertView.getResources().getDrawable(item.getAsInteger("icon")));
            }
        }

        return convertView;
    }
}
  • 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-24T07:09:45+00:00Added an answer on May 24, 2026 at 7:09 am

    Problem is with your xml file. Redefine tasks_dialog_item.xml as this;

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="?android:attr/listPreferredItemHeight"
        android:padding="6dip">
    
        <ImageView android:id="@+id/item_icon" 
            android:layout_width="wrap_content" 
            android:layout_height="fill_parent"
            android:layout_alignParentTop="true" 
            android:layout_alignParentBottom="true"
            android:layout_marginRight="6dip" 
            android:src="@drawable/icon" />
    
        <LinearLayout android:orientation="vertical" 
                      android:layout_toRightOf="@id/item_icon"
                      android:layout_width="fill_parent" 
                      android:layout_height="wrap_content">
    
            <TextView android:id="@+id/item_title" 
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" 
                android:text="My Application" />    
    
            <TextView  android:id="@+id/item_subtitle" 
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" 
                android:text="Simple application that shows how to use RelativeLayout"
                android:ellipsize="marquee" 
                android:singleLine="true" />
    
        </LinearLayout>
    
    </RelativeLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I extended a ModelAdmin with a custom field Download file, which is a link
I've got an extended WebBrowser control which handles the NewWindow3 event. Originally I wanted
I extended the default image plugin with a checkbox labelled 'Activate Zoom'. If the
I extended Array to support indexOf in IE using this JavaScript function from Mozilla
I have an extended from BaseAdapter class which used as a custom Adapter for
I have an extended GridView class, GridViewEx, which inherits from the basic ASP.NET gridview.
In the sun extended RMI tutorial, they have some interesting code which implements a
I have a JTable (extended) and an implementation of TableModel , in which I
I would like to extended DataGridView to add a second ContextMenu which to select
I have an extended RelativeLayout which, when programmatically positioned and sized using RelativeLayout.LayoutParams ,

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.