2011-10-26 51 views
0

所以我一直在工作一段時間,似乎無法弄清楚這darn ListView業務.. 我曾在另一個應用程序工作,但當我複製粘貼(我知道)它沒有工作。 因此,環顧大約6個小時後,我決定來這裏。驚喜!另一個ListView的死衚衕.. LV不會顯示

此代碼執行時沒有錯誤,但不會在ListView上顯示任何內容。我最終想要做的是在底部添加一個按鈕,與ListView分開。

(P.S)我做了8個空間,就像我應該有的,我不知道爲什麼代碼沒有顯示,這是關於我今天的運氣。

下面是Java代碼:

Edit: posted the wrong files, here is the right code. (broken) 

    public class ShittyAdapter extends ListActivity{ 
Context context; 
public ShittyAdapter(){ 
    context = this; 

} 
//variables go here 


String[] temp; 
ArrayList<SearchResults> results = new ArrayList<SearchResults>(); 
SearchResults sr1 = new SearchResults(); 

// called when the activity starts 
@Override 
public void onCreate(Bundle savedInstanceState){ 
    super.onCreate(savedInstanceState); 
    init(); 
    this.setListAdapter(new ArrayAdapter<String>(this, 
      R.layout.searchbutton, R.id.label, convertAryList())); 

} 
@SuppressWarnings({ "rawtypes" }) 
private ArrayList prepareList(){ 
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); 

    sr1 = new SearchResults(); 
    sr1.setName(prefs.getString("name", "0")); 
    ... 
    sr1.setEmail(prefs.getString("email", "0")); 
    return results; 
} 

public String[] convertAryList(){ 
    prepareList(); 
    temp = new String[] {...args...}; 
    System.out.println(temp); 
    return temp; 

} 

@Override 
protected void onListItemClick(ListView l, View v, int position, long id){ 
    super.onListItemClick(l, v, position, id); 
    //get clicked item 
    Object o = this.getListAdapter().getItem(position); 
    String keyword = o.toString(); 
    Toast.makeText(this, "You selected: "+ keyword, 
      Toast.LENGTH_LONG).show(); 
    switch(position){ 
    case 0: //food 
     Intent intent = new Intent(context, ShittyAdapter.class); 
      startActivity(intent); 
    break; 
    //ToDo cases for others 
    default:   
    } 



} 

}

這裏是XML:

 <?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" android:layout_height="wrap_content"> 
    <TextView android:text="@+id/TextView01" android:layout_width="wrap_content" 
    android:layout_height="wrap_content" android:id="@+id/label" 
    android:textSize="30px"></TextView> 
    </LinearLayout> 
+0

可以顯示實際填充列表的代碼(prepareList())嗎?另請發佈CustomBaseAdapter – Jack

+0

因此,請等待:'laidout.xml'文件應該包含'ListView'項目的佈局,由單個'TextView'組成,但適配器中的'ViewHolder'設置文本值至少需要兩個'TextView's,它需要從哪裏...到底在哪裏? –

+0

是的,我得到了我的文件全部交叉起來..我esperimenting與不同的觀點..我會更好地組織這一點。我已經在這方面工作了24小時以上:( – tricknology

回答

1

嘗試在你的CustomBaseAdapter下面的東西。

getCount() 
    return 10; 

getView() 
    View v = new View(); 
    //Fill width, 100px height 
    v.setLayoutParams(new ListView.LayoutParams(ListView.LayoutParam.FILL_PARENT,100));  
    v.setBackgroundColor(Color.GREEN); //Ord a random color 
    return v; 

很抱歉,如果您的適配器只包含它,它應該使列表10綠色矩形。

從那裏你可以開始做更高級的東西。

+0

謝謝所有人,在這裏找到解決方案..http://stackoverflow.com/questions/2342931/adding-a-button-underneath-a-listview-on-android現在擴大此。 – tricknology