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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:00:33+00:00 2026-05-28T07:00:33+00:00

I am trying to inflate more than one progress bar in a layout.Please tell

  • 0

I am trying to inflate more than one progress bar in a layout.Please tell me if there is any thing wrong with layouts. I have a xml code battery.xml:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="horizontal" android:background="#FFFFFF">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"

        android:orientation="vertical" 
        android:id="@+id/batteryholder">

        <TextView android:text="Test ID: 137" android:gravity="left"
            android:id="@+id/test_id" android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:textSize="14dip"
            android:paddingLeft="30dip" android:paddingTop="10dip"
            android:textColor="#000000" />

        <HorizontalScrollView
            android:id="@+id/scroll_battery"
            android:layout_width="420dip"
            android:layout_height="200dip"
            android:layout_marginTop="0dip" >

and another file batterylayout.xml:

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

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/empty_battery" />

    <ProgressBar
        android:id="@+id/vertical_progressbar"
        style="@style/Widget.ProgressBar.Vertical"
        android:layout_width="88dp"
        android:layout_height="150dp"
        android:layout_x="2dp"
        android:layout_y="23dp" />

</AbsoluteLayout>


<AbsoluteLayout
    android:id="@+id/scrolllinearlayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

        </AbsoluteLayout>

        </HorizontalScrollView>
</LinearLayout>

how could i inflate more than one batterylayout in battery.xml.Plz help.

My java code is:

setContentView(R.layout.battery);
batteryHolder = (LinearLayout)batteryHolder.findViewById(R.id.batteryholder);
((TextView) findViewById(R.id.test_id)).setText(Html.fromHtml("<b>Test ID:</b>"+Student_record.getString(3)));
scrollview_battery = (HorizontalScrollView)scrollview_battery.findViewById(R.id.scroll_battery);
scrolllayout_battery = (AbsoluteLayout)scrolllayout_battery.findViewById(R.id.scrolllinearlayout);

LayoutInflater inflater = getLayoutInflater();
LinearLayout battery = (LinearLayout)inflater.inflate(R.layout.batterylayout, scrolllayout_battery, false);
ProgressBar bar= (ProgressBar)findViewById(R.id.vertical_progressbar);
bar.setMax(100);
bar.setProgress(percentage[i]);
scrolllayout_battery.addView(battery);

i am getting nullpointer at

batteryHolder = (LinearLayout)batteryHolder.findViewById(R.id.batteryholder)
  • 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-28T07:00:33+00:00Added an answer on May 28, 2026 at 7:00 am

    You get NPE because you try to access batteryHolder field which hasn’t yet been initialized. You need to inflate your battery.xml first:

    LinearLayout oneMoreBatteryLayout = (LinearLayout)inflater.inflate(R.layout.battery, null, false);
    

    And after that access your batteryholder child:

    batteryHolder = (LinearLayout)oneMoreBatteryLayout.findViewById(R.id.batteryholder);
    

    By the way, why do you need such a complicated structure? Try to simplify it.

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

Sidebar

Related Questions

Is it possible to add views to a different layout than the one called
Hi I'm trying to inflate my layout with <merge> tag here is my main.xml
I'm trying to inflate an custom alertdialog and encountered something strange. layout = inflater.inflate(R.layout.call_or_sms_dialog,(ViewGroup)findViewById(R.id.contacts));
Trying to inflate a Button code: LinearLayout ll = (LinearLayout)this.getLayoutInflater().inflate(R.layout.assets, null); Button btn =
Trying to get a wildcard search to pick up on any text in org_name
I am trying to inflate an ImageView that scales a Drawable that I can
I am very new to Android. I am trying to build inflate a context
I am trying to make my app more tablet-friendly, and so I'm trying to
I am trying to enlarge my buttons height. I am trying to inflate the
How to inflate View on layout, where all my ui elements which are on

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.