0

因此,我尝试使用从 API 获得的文件夹列表填充对话框,一旦用户单击文件夹,我将再次使用其子文件夹等填充对话框。但我不太确定所有内容如何组合在一起。至此对话框已显示,现在我需要添加实际内容。

 @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类的外观。

这就是我到目前为止所拥有的:

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,我认为这是因为适配器除了返回 null 之外没有做任何事情。

适配器返回什么?它在哪里返回它?我现在很困惑

4

1 回答 1

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;
}
}
于 2013-02-28T06:56:26.587 回答