2012-01-19 3 views
0

レイアウトで複数のプログレスバーを拡張しようとしています。レイアウトに問題があるかどうか教えてください。カスタムlayoutinflaterを使用していますか?

<?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" > 

と別のファイル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> 

どのように私はbattery.xml.Plzのヘルプで複数のbatterylayoutを膨らませることができ、私はXMLコードのbattery.xmlを持っています。

私のJavaコードは次のとおりです。

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); 

私はあなたがまだ初期化されていないbatteryHolderフィールドにアクセスしようとするので、あなたは、NPEを取得

batteryHolder = (LinearLayout)batteryHolder.findViewById(R.id.batteryholder) 
+0

どのように膨張させますか? 「レイアウト内の複数のプログレスバー」とはどういう意味ですか? –

+0

私はそれを編集しました今すぐ見てください! – Navdroid

答えて

1

でnullポインタを取得しています。あなたは膨らませる必要がある、あなたのbattery.xml最初:

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

そして、そのアクセスあなたのbatteryholderの子供の後

:ところで

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

は、なぜあなたは、このような複雑な構造が必要なのでしょうか?それを単純化してみてください。

+0

私はそれを初期化しましたが、ここには表示されません! – Navdroid

+0

いいえ、あなたはそうではありません。その特定のコード行にNPEの理由はありません。 –

+0

簡単にする方法! – Navdroid

関連する問題