1

我已经使用过 MergeAdapter 并且与 ArrayAdapter 一起工作得非常好,但是当我使用 with 时LazyAdapter extends BaseAdapter,它不会在 Logcat 上显示任何错误,并且模拟器不会显示任何 LazyAdapter 内容。

问题:

那么可以使用 BaseAdapter 和 MergeAdapter 吗?如果不是,它是我的代码,我应该怎么做?

列表片段:

public class HomeFragment extends ListFragment{



    private static final String TAG = "URL";
    private MergeAdapter adapter = null;
    private ImageView [] imageView;
    private ViewFlipper flippy;
    private ArrayList<HashMap<String, String>> newsList = new ArrayList<HashMap<String, String>>();
    private NoticiaAdapter nAdapter = null;
    // XML node keys
        static final String KEY_SONG = "news"; // parent node
        static final String KEY_ID = "id";
        static final String KEY_TITLE = "title";
        static final String KEY_TEXT = "text";
        static final String KEY_HOUR = "hour";
        static final String KEY_THUMB_URL = "thumb_url";

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onViewCreated(view, savedInstanceState);

        setRetainInstance(true);

        String[] Url = create();
        new MyAsyncTask(Url).execute();
        nAdapter = new NoticiaAdapter(getActivity(), newsList);
        adapter = new MergeAdapter();
        adapter.addView(buildlabel1());
        adapter.addAdapter(nAdapter);

        setListAdapter(adapter);
        //mergeadapter
    }

懒惰适配器:

public class NoticiaAdapter extends BaseAdapter {   

    private FragmentActivity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader; 
    ViewHolder holder = null;

    public final class ViewHolder {
        public TextView title;
        public TextView text;
        public TextView hour;
        public ImageView thumb_image;
        // public Button save_btn;

    }

     public NoticiaAdapter(FragmentActivity fragmentActivity, ArrayList<HashMap<String, String>> d) {
            super();
            this.activity = fragmentActivity;
            this.data = d;
            inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            imageLoader=new ImageLoader(activity.getApplicationContext());
        }

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


        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return data.get(position);
        }


     public long getItemId(int position) {       
      return position;   
     }   

     @Override
        public void notifyDataSetChanged() {
            super.notifyDataSetChanged();
        }

     public View getView(int position, View convertView, ViewGroup parent) {  
         View vi=convertView;
            if(convertView==null) 

                vi = inflater.inflate(R.layout.news_list_row, null);
            holder = new ViewHolder();
            holder.title = (TextView)vi.findViewById(R.id.txtTitle); // title
            holder.text = (TextView)vi.findViewById(R.id.txtDescription); // artist name
            holder.hour = (TextView)vi.findViewById(R.id.txtHour); // duration
            holder.thumb_image=(ImageView)vi.findViewById(R.id.img_news); // thumb image

            HashMap<String, String> news = new HashMap<String, String>();
            news = data.get(position);

            holder.title.setText(news.get(HomeFragment.KEY_TITLE));
            holder.text.setText(news.get(HomeFragment.KEY_TEXT));
            holder.hour.setText(news.get(HomeFragment.KEY_HOUR));
            imageLoader.DisplayImage(news.get(HomeFragment.KEY_THUMB_URL), holder.thumb_image);

      return vi;   
     }

     public void add(HashMap<String, String> map) {
            // TODO Auto-generated method stub
            data.add(map);
            notifyDataSetChanged();

        }


    }
4

1 回答 1

0

只是为了回答这个问题,我犯了一个错误,我服务器中的 xml 文件拼写错误,所以是的 MergeAdapter 与 BaseAdapter 一起使用。

所以这可能是谁想要使用的示例代码。

感谢 Commonsware 的帮助。

于 2013-01-16T20:37:28.977 回答