0

スクロールビューがある動的レイアウトを作成しようとしています。スクロール ビューでは、main.xml を参照する垂直線形レイアウトを追加しています。コードが止まるとすぐに、main.xml を参照してレイアウトを追加しようとします。

 ScrollView scroll;
    EditText search;
    Button checkin;
        LinearLayout vt;

        public void onCreate(Bundle savedInstanceState) 
        {

            super.onCreate(savedInstanceState);
            scroll=new ScrollView(getApplicationContext());
            vt=(LinearLayout) findViewById(R.id.llv);///referencing linear layout located in main.xml.This is where problem the  is occurring.
            //vt.setOrientation(LinearLayout.VERTICAL);
            scroll.addView(vt);
            this.setContentView(scroll);
        }

main.xml (R.id.llv がある場所)

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



    <LinearLayout
        android:id="@+id/llv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
         <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

        <ToggleButton
            android:id="@+id/toggleButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="ToggleButton" />

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
    </LinearLayout>

</LinearLayout>
4

3 に答える 3

1

追加してみてください

  setContentView(R.layout.main); 

前:

  vt=(LinearLayout) findViewById(R.id.llv);
于 2012-05-14T11:36:47.993 に答える
0

これを試して :

view row  = LayoutInflater.from(this).inflate(R.layout.main, null);
LinearLayout layout=row.findViewById(R.id.YourLayout);
于 2012-05-14T11:48:13.137 に答える
0

線形レイアウトを動的に作成するには、これをチェックします。

http://www.dreamincode.net/forums/topic/130521-android-part-iii-dynamic-layouts/

于 2012-05-14T12:01:00.767 に答える