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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:29:46+00:00 2026-05-24T21:29:46+00:00

I have a custom adapter for ListView and I need to return LinearLayout from

  • 0

I have a custom adapter for ListView and I need to return LinearLayout from getView(). The reason I’m doing it is that I have custom component which extends LinearLayout and need to be created from code. The problem is that if I return any LinearLayout from getView(), the application crashes. How can I get it working? I can’t inflate the View from xml, everything has to be done via code.

Here’s the getView():

@Override
public View getView(int position, View convertView, ViewGroup parent)
{
  LinearLayout lay = new LinearLayout(MyApplication.getContext()); // gets the context from extended Application class
  lay.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
  return lay;
}

And log of what happens:

08-20 08:40:07.886: DEBUG/AndroidRuntime(13039): Shutting down VM
08-20 08:40:07.896: WARN/dalvikvm(13039): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
08-20 08:40:07.926: ERROR/AndroidRuntime(13039): FATAL EXCEPTION: main
        java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
        at android.widget.ListView.setupChild(ListView.java:1870)
        at android.widget.ListView.makeAndAddView(ListView.java:1839)
        at android.widget.ListView.fillDown(ListView.java:670)
        at android.widget.ListView.fillFromTop(ListView.java:727)
        at android.widget.ListView.layoutChildren(ListView.java:1689)
        at android.widget.AbsListView.onLayout(AbsListView.java:1260)
        at android.view.View.layout(View.java:7278)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
        at android.view.View.layout(View.java:7278)
        at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
        at android.view.View.layout(View.java:7278)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
        at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1243)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1049)
        at android.view.View.layout(View.java:7278)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
        at android.view.View.layout(View.java:7278)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
        at android.view.View.layout(View.java:7278)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
        at android.view.View.layout(View.java:7278)
        at android.view.ViewRoot.performTraversals(ViewRoot.java:1172)
        at android.view.ViewRoot.handleMessage(ViewRoot.java:1921)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:143)
        at android.app.ActivityThread.main(ActivityThread.java:4196)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:507)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
        at dalvik.system.NativeStart.main(Native Method)

Thanks

// edit: If somebody could provide me with a working sample which creates LinearLayout via code and returns it from getView(), it would most likely solve this problem

  • 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-24T21:29:47+00:00Added an answer on May 24, 2026 at 9:29 pm

    Set AbsListView.LayoutParams instead of LinearLayout.LayoutParams.

    LayoutParams are to be set for a child in ViewGroup. Since your layout is a child of AbsListView you should set its layoutparams.

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

Sidebar

Related Questions

I have a ListView with a custom Adapter that extends ArrayAdapter. It's a ArrayAdapter
I have a custom ListView that uses a custom ArrayAdapter (which basically just overrides
I have a ListView powered by a custom adapter that dynamically changes the background
I have a custom ListView adapter which implements an ImageThreadLoader class. Unfortunately, the class
I have a custom ListView adapter which implements an ImageThreadLoader class. Unfortunately the class
I have a few models that need to have custom find conditions placed on
I have a listview that's populated by rows that get their data from a
I have got ListView with a custom Adapter. Every row contains clickable buttons and
I have a ListView backed by a custom adapter based on a CursorAdapter. The
I have a listview from an SQLDatabase using custom CursorAdaptor. I would like to

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.