2012-02-23 24 views
1

我這個在一個點上工作,所以我認爲我只是引用了什麼。 _regionListView似乎返回OK。我以爲ArrayList中的數組是問題,因爲它包含額外的空索引,但我認爲我沒有正確連接到ListView和TextView。Android的ArrayList中的ListView/TextView的 - 你必須提供一個資源ID爲一個TextView

任何幫助,將不勝感激。

Main.java

String _region = inRegion; 
    ParserRegion _parserRegion = new ParserRegion(); 
    InputStream _inputStream = getResources().openRawResource(R.raw.regions); 

    // Parse the Input Stream 
    _parserRegion.Parse(_inputStream, _region); 

    // Get Regions 
    List<PropertiesRegion> _regionList = _parserRegion.GetList(); 

    // Create the ArrayAdapter 
    ArrayAdapterRegion _arrayAdapter = new ArrayAdapterRegion(getApplicationContext(), R.layout.search_list, _regionList); 

    // Get reference to ListView holder 
    ListView _regionListView = (ListView) this.findViewById(R.id.regionListView); 

    // Set the ListView adapter 
    _regionListView.setAdapter(_arrayAdapter); 

Search.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:adjustViewBounds="true" 
    android:background="@drawable/search_background" 
    android:gravity="center" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:scaleType="centerCrop" > 

    <TextView 
     android:id="@+id/selectRegionTextView" 
     android:cacheColorHint="#00000000" 
     android:layout_width="wrap_content" 
     android:layout_height="30dp" 
     android:layout_marginLeft="10dip" 
     android:layout_marginRight="10dip" 
     android:layout_marginTop="150dip" 
     android:gravity="top" 
     android:textColor="#000000" 
     android:textSize="20dip" 
     android:textStyle="bold" 
     android:typeface="sans" /> 

    <ListView 
     android:id="@+android:id/regionListView" 
     android:cacheColorHint="#00000000" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_marginBottom="5dip" 
     android:layout_marginLeft="10dip" 
     android:layout_marginRight="10dip" 
     android:padding="10dp" /> 

    <Button 
     android:id="@+id/mainMenuButton" 
     android:background="@drawable/button_black" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_marginBottom="70dip" 
     android:layout_marginLeft="20dip" 
     android:layout_marginRight="20dip" 
      android:typeface="sans" 
      android:textSize="18dip" 
      android:textStyle="bold" 
      android:textColor="@android:color/white"/> 

</LinearLayout> 

Search_list.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

    <TextView 
     android:id="@+id/regionTextView" 
     android:cacheColorHint="#00000000" 
     android:gravity="center" 
     android:layout_gravity="left" 
     android:layout_width="wrap_content" 
     android:layout_height="60dp" 
     android:paddingLeft="10dip" 
     android:textColor="#000000" 
     android:typeface="sans" 
     android:textSize="20dip" 
     android:textStyle="bold"/> 

</LinearLayout> 

回答

2

從search_list.xml刪除的LinearLayout,只使用TextView的,並把這個TextView的本身

xmlns:android="http://schemas.android.com/apk/res/android" 

沒有必要LinearLayou的存在,你也可以設置機器人:layout_height =「WRAP_CONTENT」。然後它會工作。 :)

+0

完美!我很感激! – user1222760 2012-02-23 09:43:28

+0

但當然不是「andran set oid」。 – user1222760 2012-02-23 09:51:42

+0

@ user1222760對不起!我錯誤地寫了它。 – 2012-02-23 10:14:48

3

寫你search_list.xml這樣

<?xml version="1.0" encoding="utf-8"?> 

    <TextView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@android:id/text1" 
     android:cacheColorHint="#00000000" 
     android:gravity="center" 
     android:layout_gravity="left" 
     android:layout_width="wrap_content" 
     android:layout_height="60dp" 
     android:paddingLeft="10dip" 
     android:textColor="#000000" 
     android:typeface="sans" 
     android:textSize="20dip" 
     android:textStyle="bold"/> 
+0

謝謝你 - 我很感激。 – user1222760 2012-02-23 09:52:34

相關問題