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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:51:41+00:00 2026-06-04T02:51:41+00:00

I am trying to get a handle on the RelativeLayout that defines how a

  • 0

I am trying to get a handle on the RelativeLayout that defines how a row in a ListView should be laid out. I am getting null and I believe it is because one of two things.

Possibility one is that it is not inflated yet so it returns null….While I’ve read about this one I am very shaky on the inflation concept. I have been programming in Java for 3 weeks now (from C#).
So I’m not sure how to test, much less handle. For example all I do is set the adapter to the list view….not sure what event or when exactly the inflation happens under the covers.

Possibility two is that I’m not walking the tree properly.

My Parent:

<RelativeLayout 
    android:minHeight="320dp" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/rlay_LftDataParent" 
    android:orientation="vertical" >

<ListView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:id="@+id/lstvw_LiftData" />

The row definition (the layout I am trying to set the min height for)

<RelativeLayout 
    android:layout_width="fill_parent"
    android:orientation="vertical" 
    android:id="@+id/rlay_LftDataRw" 
    android:layout_height="fill_parent" 
    android:background="@drawable/background">
...
</RelativeLayout>

In the Activity I’ve tried: (lstvw_LiftData is my ListView object)

RelativeLayout RowLayout = (RelativeLayout)lstvw_LiftData.findViewById(R.id.rlay_LftDataRw);

and

RelativeLayout RowLayout = (RelativeLayout)findViewById(R.id.rlay_LftDataRw);

If you are curious to know the bigger picture this is a follow on question from this post Using RelativeLayout to control a ListView row height where I’m trying to get the row layout to fill the screen.

  • 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-04T02:51:43+00:00Added an answer on June 4, 2026 at 2:51 am

    You don’t access a View from the ListView row with findViewById. Instead use the adapter to get a reference of your RelativeLayout in the getView method and there set the width and height. You didn’t say what adapter do you use so here is a simple example for the basic ArrayAdapter:

    Edit:
    You don’t call the getView() method yourself, the adapter will call the getView method automatically when it’s time to show a new row. Regarding the question from your last comment, if the custom Adapter class is a inner class in the Activity where you’ll use it:

    public class SomeActivity extends ListActivity {
    
         private int mHeight, mWidth;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // ...do what ever stuff you need in this activity
           // find out the height/width values:
            DisplayMetrics metrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(metrics);
    
            mHeight = metrics.heightPixels;
            mWidth = metrics.widthPixels;   
            // set the adapter
            setListAdapter(new CustomAdapter(this,
                    R.layout.adapters_listview_rowheight, R.id.textView1, items));
        }
    
        //you use your own adapter class
        private class CustomAdapter extends ArrayAdapter<String> {
    
            public CustomAdapter(Context context, int resource,
                    int textViewResourceId, String[] objects) {
                super(context, resource, textViewResourceId, objects);
            }
    
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                        //do whatever logic you need here
                        // finally you end up with the RelativeLayout you'll return as the view for the row
                        // before you return set the desired values for its width and height
                rl.getLayoutParams().height = mHeight;
                rl.getLayoutParams().width = mWidth;
                return rl;
            }
    
    
        }
    
    }
    

    If you Adapter class is in another file then make the constructor of that adapter to take two int values representing the width and height:

    //the constructor
    public CustomAdapter(/*whatever parameters you already have*/, int height, int width) {
        //do stuff
        //now you also have a reference for the width and height that you can use in the getView method.
    }
    

    and in your Activity(with the same code for the onCreate method):

    setListAdapter(new CustomAdapter(/*whatever parameters you already have*/, mHeight, mWidth));
    

    I don’t know if this is what you want.

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

Sidebar

Related Questions

I am trying to get a list of receivers that handle android.intent.action.BOOT_COMPLETED for other
I am trying to get a handle on the above. I understand that an
I'm trying to get a handle to the worksheet that was created by a
I'm trying to get a handle on DDD and feel that I've got a
I am trying to get the handle of a window from a process. Now,
I'm trying to get a handle on whether we have a problem in our
I am trying to get a handle on Solrnet and interacting an ASP.NET site
I'm trying to get a handle to the foreground window in C#/Net 2.0/WinForms by
I have been trying to get a handle on using MVC 4.0 with EF
I'm trying to get a barebone app engine app to handle incoming email. I've

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.