开发者

extends BaseAdapter appear NullPointerException

i am public class MyHomePageAdapter extends BaseAdapter and some code is:

public static class ViewHolder{
    public GridView myfriendsGridView;
    public Button myfriendsPre,myfriendsNext;


    public ListView listview;
    public Button searchBu;
    public Button footerBu;
    public EditText editText;


    public ListView myfans_listview;
    public Button myfans_searchBu;
    public EditText myfans_editText;
}

 @Override
public View getView(int position, View convertView, ViewGroup parent) {
    int view = getItemViewType(position);


if(view==1)
    {
        if (convertView == null)
        {
              convertView = mInflater.inflate(R.layout.usercenter_myhome_friendschange, null);
              //holder=new ViewHolder();
              holder.listview=(ListView) convertView.findViewById(R.id.myfriend_list);
              holder.searchBu=(Button) convertView.findViewById(R.id.headbutton);
              holder.editText=(EditText) convertView.findViewById(R.id.SearchEdit);
              convertView.setTag(holder);
        }
        else
        {
             holder=(ViewHolder)convertView.getTag();
        }

        switcher = new ViewSwitcher(context);

        holder.footerBu = (Button)mInflater.inflate( R.layout.usercenter_myhomepage_myfriends_loadmore, null);
        holder.footerBu.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            ++counter;
            switcher.showNext();


                //new getMyFriendsMoreItems().execute();  

                    if(NUMBER_OF_ITEMS_IN_COLUMN+counter*NUMBER_OF_MOVE>ConstValue.myfriendsListInfo.size())
                    {

                        MyFriendssubSet=getDataSubset(0,ConstValue.myfriendsListInfo.size(),ConstValue.myfriendsListInfo);

                    }
                    else
                     {  
                        MyFriendssubSet=getDataSubset(0, NUMBER_OF_ITEMS_IN_COLUMN+counter*NUMBER_OF_MOVE,ConstValue.myfriendsListInfo);

                     }


                    if(MyFriendssubSet.size()>0)
                    {

                        adapter.setMasteList(MyFriendssubSet);
                        adapter.notifyDataSetChanged();

                    }
                    switcher.showPrevious();
                    Log.i("aa", "rr: "+holde开发者_运维知识库r.listview);
                    //holder.listview.setSelection(MyFriendssubSet.size()-1-NUMBER_OF_MOVE);

          }
        });

          View progress = mInflater.inflate(R.layout.usercenter_myhome_myfriends_loading_footer, null);
          switcher.addView(holder.footerBu);
          switcher.addView(progress);
          holder.listview.addFooterView(switcher);

         if(ConstValue.myfriendsListInfo.size() > 0)
         {

             MyFriendssubSet=getDataSubset(0, NUMBER_OF_ITEMS_IN_COLUMN, ConstValue.myfriendsListInfo);
             adapter =new FriendsLazyAdapter((Activity) context, MyFriendssubSet);
             holder.listview.setAdapter(adapter);
         }

i found that my mistake is in this :

switcher.showPrevious(); Log.i("aa", "rr: "+holder.listview); //holder.listview.setSelection(MyFriendssubSet.size()-1-NUMBER_OF_MOVE); the holder.listview=null,so if i delete "//" can call holder.listview.setSelection(MyFriendssubSet.size()-1-NUMBER_OF_MOVE); it weill appear NullPointerException ,so my question how to used the holder.listview so that it not null


i have modify the code:

              lv=holder.listview;
          View progress = mInflater.inflate(R.layout.usercenter_myhome_myfriends_loading_footer, null);
          switcher.addView(holder.footerBu);
          switcher.addView(progress);
          lv.addFooterView(switcher);

         if(ConstValue.myfriendsListInfo.size() > 0)
         {

             MyFriendssubSet=getDataSubset(0, NUMBER_OF_ITEMS_IN_COLUMN, ConstValue.myfriendsListInfo);
             adapter =new FriendsLazyAdapter((Activity) context, MyFriendssubSet);
             lv.setAdapter(adapter);
         }

i put the holder.listview to a new ListView,the problem is solve

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜