我曾在一個XML文件中相對佈局下面讓我們說add_relative_layout.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="vertical"
android:id="@+id/addAccountLinearLayout">
</LinearLayout>
以上是我想添加的代碼文件拷貝以下主要佈局。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/UIContainer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/white" >
<TextView
android:id="@+id/amountLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:text="Amount"
android:textColor="@android:color/black"
android:textStyle="bold" />
<EditText
android:id="@+id/amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp" >
</EditText>
我命名爲Show_all.xml另一個Android XML文件。這是一個線性佈局XML
我想,因爲我在這個SHOW_ALL佈局
目前想我使用這個代碼上方添加儘可能多的時候,這相對佈局
private void callOnCreate()
{
linear = (LinearLayout) findViewById(R.id.addAccountLinearLayout); // the layout in which i want to make dynamic copies of this layout.
layout = (RelativeLayout) findViewById(R.layout.ui_relative_layout_style); // name of xml File of above code.
for (int i=0; i < 4; i++)
{
Account account = accountArray.get(i);
linear.addView(layout, i);
}
}
我得到空點例外。請告訴我應該怎麼做 。
問候
,你得到空指針異常。請發佈logcat,以便它可以幫助我們回答您的問題。 – deepa 2012-03-01 04:23:41
@umar將您的完整logcat和NullPointerexception提供給您。您的活動檢查哪一行提供空值 – 2012-03-01 04:29:19