问题描述
我是公共类MyHomePageAdapter扩展了BaseAdapter有的code是:
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: "+holder.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.show previous();
Log.i(AA,RR:+ holder.listview);
//holder.listview.setSelection(MyFriendssubSet.size()-1-NUMBER_OF_MOVE);
在holder.listview = NULL,所以如果我删除//可以调用holder.listview.setSelection(MyFriendssubSet.size() - 1 - NUMBER_OF_MOVE);它威尔出现NullPointerException异常,所以我的问题是如何使用的holder.listview,使其不为空
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
推荐答案
我有修改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);
}
我把holder.listview到一个新的ListView,问题是解决
i put the holder.listview to a new ListView,the problem is solve
这篇关于扩展了BaseAdapter出现NullPointerException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!