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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:31:35+00:00 2026-06-17T15:31:35+00:00

I have a ListView which is supposed to become a menu with two drawables

  • 0

I have a ListView which is supposed to become a menu with two drawables and two text views per row.

Activity Code:

ArrayList<MenuItem> itemArray = new ArrayList<MenuItem>();
        itemArray.add(new MenuItem("Headertexxt", "subbtexdt"));
        itemArray.add(new MenuItem("asf", "asf"));

        ListView listView = (ListView) findViewById(R.id.listViewCM);

        String[] array = getResources().getStringArray(R.array.buttonsCM);
        int[] images =  new int[] { R.drawable.btn_car, R.drawable.btn_star, R.drawable.btn_bag};
        listView.setAdapter(new HomeScreenButtonsAdapterSubtext(this, R.layout.row,
                itemArray, images, R.drawable.list_arrow));

        Utils.setListViewHeightBasedOnChildren(listView);
        listView.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position) {
                case 0:
                    findViewById(R.id.buttonCreditCompilation).performClick();
                    break;
                case 1:
                    findViewById(R.id.buttonYourCredits).performClick();
                    break;

                }
            }
        });

Adapter code:

public class HomeScreenButtonsAdapterSubtext extends ArrayAdapter<MenuItem> {

        private Drawable[] drawables;

        private Drawable arrowDrawable;
        private ArrayList<MenuItem> items;

        public HomeScreenButtonsAdapterSubtext(Context context, int resourceId,
                ArrayList<MenuItem> items, int[] images, int arrowImage) {
            super(context, resourceId, items);
            this.items = items;

            Resources resources = context.getResources();
            if (images != null) {
                drawables = new Drawable[images.length];
                int i = 0;
                for (int id : images) {
                    Drawable drawable = resources.getDrawable(id);
                    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
                            drawable.getIntrinsicHeight());
                    drawables[i++] = drawable;
                }
            }

            arrowDrawable = resources.getDrawable(arrowImage);
            arrowDrawable.setBounds(0, 0, arrowDrawable.getIntrinsicWidth(),
                    arrowDrawable.getIntrinsicHeight());
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
             View v = super.getView(position, convertView, parent);
             if (v instanceof TextView) {
             Drawable dr = drawables != null ? drawables[position %
             drawables.length] : null;
             ((TextView) v).setCompoundDrawables(dr, null, arrowDrawable, null);
             Utils.setFont((TextView) v);
             }

//          View v = convertView;
            if (v == null) {
                LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.row, null);
            }

            MenuItem station = items.get(position);
            if (station != null) {
                TextView tt = (TextView) v.findViewById(R.id.headerText);
                TextView bt = (TextView) v.findViewById(R.id.subText);


                if (tt != null) {
                    tt.setText(station.getHeaderText());
                }
                if (bt != null) {
                    bt.setText(station.getSubText());
                }

            }

            return v;
        }

The problem I have right now is that I can’t set the listview height based on the children. I’m trying to do that here: Utils.setListViewHeightBasedOnChildren(listView); but getting the error: arrayadapter requires the resource id to be a textview at this row. Does anyone know a solution for this?

Can I use some other method for setting the ListView height?

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-17T15:31:36+00:00Added an answer on June 17, 2026 at 3:31 pm

    but getting the error: arrayadapter requires the resource id to be a
    textview at this row.

    R.layout.row is a layout file which it doesn’t have just a TextView. If you call the super constructor you have used and you also call the super.getView(in the getView method) method in the adapter, then ArrayAdapter will complain as it expects a single widget in the layout file passed to it(a single TextView).

    I don’t understand why you have that piece of code in the getView method(with the super call) when you know precisely that the row can’t be an instance of Textview .

    I’m not sure about setting the height of the ListView either, if you’re trying to show all the rows of the ListView, don’t do it(as you make the ListView basically useless). If you still want to do this, then it’s better to lose the ListView and build the row layouts manually.

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

Sidebar

Related Questions

I have a ListView which contains custom rows. This custom row has following UI
I have listView in which I inflate a row contain textview and button now
I have a ListView which is populated using a SimpleCursorAdapter. The row layout is
I have ListView which as one TextView in each Row. and im discovering some
I have a ListView which has bound data, and two additional bindings like this:
I have a listview which contains maybe 15 rows. Each row (list item) contains
I have a ListView which I'm binding to a CollectionViewSource in code behind with:
I have ListView which is saving all data to database. For adding i have
I have a ListView which displays a list of string values. I want to
I have a ListView which might contains a lot of items, so it is

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.