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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:02:46+00:00 2026-06-15T11:02:46+00:00

i wanted to have a custom listView so I did this: Created an Activity:

  • 0

i wanted to have a custom listView so I did this:

Created an Activity:

public class PRS_MainList_Act extends ListActivity {
    MainListAdapter mladp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_prs__main_list_);
        ArrayList<MainMenuItem> menuItems = new ArrayList<MainMenuItem>();
        menuItems.add(new MainMenuItem(getResources().getString(R.string.main_list_connectivity), getResources().getString(R.string.main_list_connectivityDesc)));
        this.mladp = new MainListAdapter(this, R.layout.man_list_item, R.id.textView1, menuItems);
        setListAdapter(mladp);

    }
}

Create a class for menu items:

public class MainMenuItem {

    private String itemText;
    private String itemDescription;
    private String itemIMG;
    private int itemWeight;
    private String itemAssociatedActivity;

    public MainMenuItem(String itemText, String itemDescription) {
        this.itemText = itemText;
        this.itemDescription = itemDescription;
    }

    public String getItemText() {
        return itemText;
    }
    public void setItemText(String itemText) {
        this.itemText = itemText;
    }
    public String getItemIMG() {
        return itemIMG;
    }
    public void setItemIMG(String itemIMG) {
        this.itemIMG = itemIMG;
    }
    public int getItemWeight() {
        return itemWeight;
    }
    public void setItemWeight(int itemWeight) {
        this.itemWeight = itemWeight;
    }
    public String getItemAssociatedActivity() {
        return itemAssociatedActivity;
    }
    public void setItemAssociatedActivity(String itemAssociatedActivity) {
        this.itemAssociatedActivity = itemAssociatedActivity;
    }

    public String getItemDescription() {
        return itemDescription;
    }

    public void setItemDescription(String itemDescription) {
        this.itemDescription = itemDescription;
    }

}

Custom array adapter:

public class MainListAdapter extends ArrayAdapter<MainMenuItem> {

    ArrayList<MainMenuItem> menuItems;

    public MainListAdapter(Context context, int resource,
            int textViewResourceId, ArrayList<MainMenuItem> menuItems) {
        super(context, resource, textViewResourceId, menuItems);
        this.menuItems = menuItems;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        if (convertView == null) {
            LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
                    Context.LAYOUT_INFLATER_SERVICE);
            view = vi.inflate(R.layout.man_list_item, parent);
        }
        MainMenuItem it = menuItems.get(position);
        if (it != null) {
            TextView titleTV = (TextView) view.findViewById(R.id.textView1);
            TextView descriptionTV = (TextView) view.findViewById(R.id.textView2);
            ImageView iconIV = (ImageView)view.findViewById(R.id.imageView1);
            if (titleTV != null) {
                titleTV.setText(it.getItemText());
            }
            if(descriptionTV != null){
                descriptionTV.setText(it.getItemDescription());
            }
            if(iconIV != null){
                if(it.getItemText().equals(getContext().getResources().getString(R.string.main_list_connectivity)))
                    iconIV.setImageResource(R.drawable.network_connections);
            }
        }
        return view;
    }

}

and here are my activity layout and item layout:

<LinearLayout 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"
    tools:context=".PRS_MainList_Act" >
    <ListView android:id="@android:id/list"
        android:layout_height="match_parent"
        android:layout_width="match_parent"/>

</LinearLayout>

Item Layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:src="@drawable/ic_launcher" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:text="Medium Text"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:text="TextView" />

    </LinearLayout>

</LinearLayout>

I got this error saying: java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView

Thanks in advance for your help.

  • 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-15T11:02:46+00:00Added an answer on June 15, 2026 at 11:02 am

    You can’t use this version of the inflate method:

    view = vi.inflate(R.layout.man_list_item, parent);
    

    because this will add the inflated View to the parent, which isn’t allowed in a ListView. Instead use this version:

    view = vi.inflate(R.layout.man_list_item, parent, false);
    

    which will inflate the view but will not add it to the parent. This version is important because it will provide the proper LayoutParams for your inflated view.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a custom view class because I wanted to have a status item
I've created a a custom activity designer, but I wanted to have control over
I have a listview in which i wanted to have custom typeface e.g. Arial.
I have created a listview that sits inside a larger activity (the list view
I've created a custom adapter for my spinner because I wanted to have multiple
I have 2 custom post types - offered and wanted. I want these items
I have a custom defined table in sonar DB , and I wanted to
I wanted to use the custom field for wordpress to have a different header
So I wanted to have something like in this image . Basically you have
Say I wanted to have one variable in a class always be in some

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.