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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:37:39+00:00 2026-05-25T22:37:39+00:00

I am attempting to set variable left margins for items in my ListView. The

  • 0

I am attempting to set variable left margins for items in my ListView. The problem occurs in my custom Adapter in the getView method:

    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null){
            Comment c = comments.get(position);
            convertView = inflater.inflate(R.layout.list_item, null);               
            (TextView)convertView.findViewById(R.id.story)).setText(c.message);


        }
            RelativeLayout.LayoutParams lp = new  RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
            lp.setMargins(0, c.getDepth() * 5, 0, 0);               
            convertView.setLayoutParams(lp);

        return convertView;
    }

We inflate the list_item layout which is a RelativeLayout with some textViews inside. I then attempt to set the margins using a RelativeLayout.LayoutParams. I get a class cast exception on this, but the normal LayoutParams type has no method for setting the margins.

What is the best way to go about setting the margin?

Here is the error

java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams
at android.widget.ListView.setupChild(ListView.java:1779)
at android.widget.ListView.makeAndAddView(ListView.java:1748)
at android.widget.ListView.fillDown(ListView.java:670)
at android.widget.ListView.fillFromTop(ListView.java:727)
at android.widget.ListView.layoutChildren(ListView.java:1598)
at android.widget.AbsListView.onLayout(AbsListView.java:1273)
at android.view.View.layout(View.java:7192)
at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
at android.view.View.layout(View.java:7192)
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:7192)
at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
at android.view.View.layout(View.java:7192)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1145)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3835)
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:847)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
at dalvik.system.NativeStart.main(Native Method)
  • 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-25T22:37:40+00:00Added an answer on May 25, 2026 at 10:37 pm

    I found the simplest way to solve this problem was to simply wrap my item in a FrameLayout in the xml. I could then easily set the left padding as I wished thus giving me the exact look I was hoping for.

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

Sidebar

Related Questions

I am attempting to manipulate an asp.net MVC2 view variable in Jquery... (function ()
I’m attempting to set up a variable-based object operator in PHP, but am only
A make script is attempting to set a variable as follows: VER_DEC=$( perl -e
I am attempting to set an asp.net textbox to a SQL 2005 money data
I'm attempting to set up a symbol proxy using symproxy.dll from Debugging Tools for
I am attempting to set a value in a textarea field using jquery with
I'm attempting to set up basic logging to the windows event log in .net
I am attempting to set up my own project using a third party library
I have a Perl script that I'm attempting to set up using Perl Threads
Possible Duplicate: C# generic constraint for only integers Greets! I'm attempting to set up

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.