2011-02-07 7 views
1

私はです。Androidで開発を開始したのはなので、これは非常に基本的なことですが、 。 。インラインListViewを設定するにはどうすればよいですか?

ListViewLinearLayoutに設定するのは本当に苦労しています。たぶんそれは私のXMLレイアウトの問題、またはおそらく私のデータバインディングコードの問題です。

多くのチュートリアルでは、私のActivityListActivityになるはずです。なぜこの1つのウィジェットは私のUI全体が変更される必要がありますか?

私は、アイテムのスクロールボックスがこの1つの画面の一部を占有したいだけです。 ListViewは間違ったウィジェットを使用しますか?代わりにScrollViewを使用する必要がありますか?

おかげ - ここは私のXMLです:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#FFF" 
    > 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/enter_text" 
     /> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"> 

     <EditText 
      android:id="@+id/txtTo" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="left" 
      android:layout_weight="1" 
      android:width="200px"/> 
     </LinearLayout> 
     <ListView android:id="@+id/listRecent" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 
    </LinearLayout> 

そしてここでは、私のコードです:

public class MyApp extends Activity { 

private String TAG = "MyApp"; 

//UI ELEMENTS 
EditText txtTo; 
ListView listRecent; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    //GET REFERENCES TO UI ELEMENTS 
    listRecent = (ListView) this.findViewById(R.id.listRecent); 

    try { 

     //---------------------------------------- 
     // create the grid item mapping 
     String[] from = new String[] {"zero", "one", "two", "three"}; 
     int[] to = new int[] {0, 1, 2, 3}; 

     // prepare the list of all records 
     List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>(); 
     for(int i = 0; i < 10; i++){ 
      HashMap<String, String> map = new HashMap<String, String>(); 
      map.put("rowid", "" + i); 
      map.put("col_1", "col_1_item_" + i); 
      map.put("col_2", "col_2_item_" + i); 
      map.put("col_3", "col_3_item_" + i); 
      fillMaps.add(map); 
     } 

     // fill in the grid_item layout 
     SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.recently_dingdonged, from, to); 
     listRecent.setAdapter(adapter); 
     //---------------------------------------- 

    } 
    catch(Exception e) { 
     Log.e(TAG, "Error here (3116019)", e); 
    } 

} 

答えて

0

ActivityListActivityを延長する必要はありません。できますが、それは必要ではありません。あなたのXMLに関連して

、これを試してみる:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#FFF" 
    > 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/enter_text" 
     /> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 

     <EditText 
      android:id="@+id/txtTo" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:gravity="left" 
      android:layout_weight="0.5" 
      android:width="200px"/> 
     </LinearLayout> 
     <ListView android:id="@+id/listRecent" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.5" /> 
    </LinearLayout> 
+0

はそれを手に入れた - ありがとう:) – marclar

1

リストビューはscrollviewの内部にネストされなければなりません。 listActivityを拡張すると、setAdapterの機能が得られ、リストをインスタンス化するのではなく、メインオブジェクトを通じてリストビューにデータを取り込みます。しかしこれは決して要件ではありません。

関連する問題