我曾在一个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