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

  • Home
  • SEARCH
  • 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 8653867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:38:46+00:00 2026-06-12T14:38:46+00:00

I tried to create custom ViewGroup class, but when I used method findViewById() it

  • 0

I tried to create custom ViewGroup class, but when I used method findViewById() it returns null, but inflating the view is ok.

code is:

public class HorizontalListView extends ViewGroup 
{
    private int mNumber = 0;
    private ImageView mImage;
    private LinearLayout mAdapter;

    public HorizontalListView(final Context context, final AttributeSet set)
    {
        super(context, set);
        LayoutInflater.from(getContext()).inflate(R.layout.layout_horizontal_list_view, this, false);

        mAdapter = (LinearLayout) getChildAt(0);
    }

    /**Adds ImageView to LinearLayout (Adapter)
     * g
     * @param image
     */
    public void addView(final Bitmap image)
    {
        mImage = (ImageView) LayoutInflater.from(getContext())
                                    .inflate(R.layout.create_added_photo, null);
        mImage.setImageBitmap(image);
        mImage.setTag(mNumber);
        mNumber++;
        mAdapter.addView(mImage);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) 
    {
        // TODO Auto-generated method stub

    }

}

here mAdapter.addView(mImage); I have a NullPointerException

xml code:

<?xml version="1.0" encoding="utf-8"?>  
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center_vertical"
        android:id="@+id/list_for_new_photos">

    </LinearLayout>

</HorizontalScrollView>
  • 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-12T14:38:47+00:00Added an answer on June 12, 2026 at 2:38 pm

    Change your code as follows

    public HorizontalListView(final Context context, final AttributeSet set) {
        super(context, set);
        View view = LayoutInflater.from(getContext()).inflate(R.layout.layout_horizontal_list_view, this, false);
        mAdapter = (LinearLayout) view.getChildAt(0);
    }
    

    or

    public HorizontalListView(final Context context, final AttributeSet set) {
        super(context, set);
        View view = LayoutInflater.from(getContext()).inflate(R.layout.layout_horizontal_list_view, this, false);
        mAdapter = (LinearLayout) view.findViewById(R.id.list_for_new_photos);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to create a custom button class and use it. But it works
I tried to create a custom .NET attribute with the code below but accidentally
I tried to create a custom ValidationAttribute: public class RollType : ValidationAttribute { public
i tried to create a custom content type in drupal but unnecessary features like
I have tried create this table, but nothing I have tried works from FKs.
Tried to create a mobile navigation using dataview or outline and the view renders
I tried to create a code that adds 2 percent each time a component
I tried to create a custom control, having a semitransparent rounded background: <Canvas> <TextBlock
Using this I tried to create a custom ListAdapter that would simply add all
How to create a custom login system with google-app-engine's User class? I'm making my

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.