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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:45:21+00:00 2026-06-04T16:45:21+00:00

I have asked this question before with other adapters like SimpleAdapter but the solution

  • 0

I have asked this question before with other adapters like SimpleAdapter but the solution for the simple adapter is not working for ArrayAdapter. In a SimpleAdapter I got the screen width & height then passed that to my RelativeLayout for the data row. The effect was that only one record filling the entire screen was shown at a time. That was fine with static data but now I want to use mutable data.

In short I really don’t want to pass the height and width at all. My XML layout is using dip so the screen sizes can change all they want. What I am REALLY after is a way to control the getView call to just one record at a time.

Anyway using the workaround from SimpleAdapter I thought passing the height and width just like before would work but for some reason this time I’m getting an error I can’t figure out. Here is the code that sets the width and height:

RelativeLayout.LayoutParams szParms = new RelativeLayout.LayoutParams(mWidth, mHeight);
vw_BigRow.setLayoutParams(szParms);

The height and width are determined elsewhere and are accurate across all devices I’ve tested with.
Not really sure what else to post so just tell me and I add that code / info to the question.

E/AndroidRuntime(404): FATAL EXCEPTION: main
E/AndroidRuntime(404): java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams

Edit

As has been correctly pointed out my error occurs with a CastClassException however I am still not doing the assignment right as I continue to get the error. I have tried in the activity to set the height / width with the following:

AbsListView.LayoutParams szParms = new AbsListView.LayoutParams(mWidth, mHeight);
lstvw_LiftData.setLayoutParams(szParms);

E/AndroidRuntime(1886): FATAL EXCEPTION: main
E/AndroidRuntime(1886): java.lang.ClassCastException: android.widget.AbsListView$LayoutParams

and

ListView.LayoutParams szParms = new ListView.LayoutParams(mWidth, mHeight);
lstvw_LiftData.setLayoutParams(szParms);

E/AndroidRuntime(1886): FATAL EXCEPTION: main
E/AndroidRuntime(1886): java.lang.ClassCastException: android.widget.AbsListView$LayoutParams

the lstvw_LiftData is a valid ref and not null.

Inside the getView() override of the ArrayAdapter I also try to set the values with the same result

@Override 
public View getView(int position, View convertView, ViewGroup parent) 
{...}

The only thing I can get to work is this and then a couple, Not All, but a couple of my elements are ignoring their layout positioning and going straight to the bottom.

View vw_BigRow = convertView;
    
if (vw_BigRow == null) 
{
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    vw_BigRow = inflater.inflate(R.layout.liftdatalayout, null);
}
    
vw_BigRow.setMinimumHeight(mHeight);
vw_BigRow.setMinimumWidth(mWidth);
  • 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-04T16:45:23+00:00Added an answer on June 4, 2026 at 4:45 pm

    1.If you want call to just one record at a time, just control the getCount of the adapter you implemented to return 1.

    2.The java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams exception is because the view want added to the listview should use AbsListView.LayoutParams instead of other LayoutParams such as RelativeLayout$LayoutParams.

    EDIT:

    See below getView code which is recommended by google.

    /**
     * Make a view to hold each row.
     *
     * @see android.widget.ListAdapter#getView(int, android.view.View,
     *      android.view.ViewGroup)
     */
    public View getView(int position, View convertView, ViewGroup parent) {
        // A ViewHolder keeps references to children views to avoid unneccessary calls
        // to findViewById() on each row.
        ViewHolder holder;
    
        // When convertView is not null, we can reuse it directly, there is no need
        // to reinflate it. We only inflate a new View when the convertView supplied
        // by ListView is null.
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.list_item_icon_text, null);
    
            // Creates a ViewHolder and store references to the two children views
            // we want to bind data to.
            holder = new ViewHolder();
            holder.text = (TextView) convertView.findViewById(R.id.text);
            holder.icon = (ImageView) convertView.findViewById(R.id.icon);
    
            convertView.setTag(holder);
        } else {
            // Get the ViewHolder back to get fast access to the TextView
            // and the ImageView.
            holder = (ViewHolder) convertView.getTag();
        }
    
        // Bind the data efficiently with the holder.
        holder.text.setText(DATA[position]);
        holder.icon.setImageBitmap((position & 1) == 1 ? mIcon1 : mIcon2);
    
        return convertView;
    }
    
    static class ViewHolder {
        TextView text;
        ImageView icon;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Variations of this question have been asked before, but it seems like the issue
I have asked this before but I didn't get the question right so the
This question may have been asked before, but I had trouble finding an answer,
No doubt elements of this question have been asked before, but I'm having trouble
I know variants of this question have been asked before (even by me), but
I have asked this before, but the more I look at other code examples
I have asked other AI folk this question, but I haven't really been given
I have asked a question on this before, but again ran into problems and
I'm sure some variation of this question has been asked before but all other,
I'm sorry if this question has been asked before, but I'm not even sure

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.