2013-02-28 94 views
0

因此,我試圖填充一個對話框與我從API獲取的文件夾列表,一旦用戶點擊一個文件夾,我再次填充對話框及其子文件夾等但我不太清楚所有東西是如何結合在一起的。到目前爲止,顯示對話框,現在我需要添加實際內容。適配器和DialogView - 不知道如何構建適配器

@Override 
protected View onCreateDialogView() { 

    LayoutInflater inflater = ((SettingsActivity) ctx).getLayoutInflater(); 
    View vw = inflater.inflate(R.layout.channel_content_view, null); 
    ListView lv = (ListView) vw.findViewById(android.R.id.list); 
    File[] files = ChannelHandler.getChannels(); 
    HiddenChannelsListAdapter adapter = new HiddenChannelsListAdapter(ctx, files); 
    lv.setAdapter(adapter); 
    return vw; 
} 

林不知道那類HiddenChannelsListAdapter如何要看。

這是我SOFAR:

package com.example.tvrplayer; 

import java.io.File; 

import android.app.Activity; 
import android.content.Context; 
import android.util.Log; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.BaseAdapter; 

public class HiddenChannelsListAdapter extends BaseAdapter { 
    public HiddenChannelsListAdapter(Context ctx, File[] files) { 
     // TODO Auto-generated constructor stub 
    } 

    @Override 
    public int getCount() { 
     // TODO Auto-generated method stub 
     return 0; 
    } 

    @Override 
    public Object getItem(int arg0) { 
     // TODO Auto-generated method stub 
     return null; 
    } 

    @Override 
    public long getItemId(int arg0) { 
     // TODO Auto-generated method stub 
     return 0; 
    } 

    @Override 
    public View getView(int arg0, View arg1, ViewGroup arg2) { 
     View view = null; 
     Log.i("ADAPTER", "Hello"); 
     return view; 
    } 

} 

當我嘗試,現在打開的對話框中,它得到一個NullPointerException,我asume是因爲適配器沒有做任何事情,但返回null。

適配器返回什麼?它在哪裏返回?林此刻

回答

2

很困惑嘗試這樣

public class ContactListCursorAdapter extends BaseAdapter { 

/** Remember our context so we can use it when constructing views. */ 
private Context mContext; 

/** 
* Hold onto a copy of the entire Contact List. 
*/ 
private List<ContactEntry> mItems = new ArrayList<ContactEntry>(); 

public ContactListCursorAdapter(Context context, ArrayList<ContactEntry> items) { 
    mContext = context; 
    mItems = items; 
} 

public int getCount() { 
    return mItems .size(); 
} 

public Object getItem(int position) { 
    return mItems .get(position); 
} 

/** Use the array index as a unique id. */ 
public long getItemId(int position) { 
    return position; 
} 

/** 
* @param convertView 
*   The old view to overwrite, if one is passed 
* @returns a ContactEntryView that holds wraps around an ContactEntry 
*/ 
public View getView(int position, View convertView, ViewGroup parent) { 
    ContactEntryView btv; 
    if (convertView == null) { 
     btv = new ContactEntryView(mContext, mShow.get(position)); 
    } else { 
     btv = (ContactEntryView) convertView; 
     String name = mShow.get(position).getName(); 
     btv.setNameText(name); 
     String number = mShow.get(position).getNumber(); 
     if (number != null) { 
       btv.setNumberText("Mobile: " + mShow.get(position).getNumber()); 
     } 
    } 
     return btv; 
} 
} 
+0

在我來說,我將不會返回文件[]列表,而是一個JSONArray。 – Harry 2013-02-28 10:04:12