自定义的MyGridAdapter执行时,getcount()返回值为空
/*
* 自定义控件
*/
package com.My_Music.Music_Guess.my_ui;
import java.util.ArrayList;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import com.My_Music.Music_Guess.R;
import com.My_Music.Music_Guess.model.WordButton;
import com.My_Music.Music_Guess.util.Util;
public class MyGridView extends GridView {
/*
* 常量声明
*/
public final static int COUNT_WORD=24;
/*
* 变量声明
*/
private ArrayList<WordButton> mWordButtonButtomList; //定义容器(存储下按钮)
private MyGridAdapter mAdapter; //定义适配器
private Context mContext;
private WordButton holder;
/*
* 自定义MyGridView
*/
public MyGridView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
Log.v("MyGridView", "ok");
MyGridAdapter mAdapter=new MyGridAdapter();
// TODO Auto-generated constructor stub
this.setAdapter(mAdapter); //将MyGridAdapter与MyGridView相关联
Log.v("MyGridView2", "ok");
mContext=context;
}
/*
* 自定义MyGridAdapter适配器
*/
class MyGridAdapter extends BaseAdapter{
@Override
public int getCount() { //返回多少个
// TODO Auto-generated method stub
if(mWordButtonButtomList.size()==24)
Log.v("getcount", "ok");
if(mWordButtonButtomList.size()==0)
Log.v("getcount", "0");
return mWordButtonButtomList.size();
}
@Override
public Object getItem(int pos) { //返回当前选中的item对象
// TODO Auto-generated method stub
return mWordButtonButtomList.get(pos);
}
@Override
public long getItemId(int pos) { //返回当前选中的item的id
// TODO Auto-generated method stub
return pos;
}
@Override
public View getView(int pos, View v, ViewGroup p) { //返回当前选中对象的view
// TODO Auto-generated method stub
Log.v("getview"+"1", holder.mWordString);
if(v==null)
{ v=Util.getView(mContext,R.layout.word_button_buttom); //载入文字按钮界面
holder=mWordButtonButtomList.get(pos);
holder.index=pos;
holder.mViewButton=(Button)findViewById(R.id.per_button_buttom); //将holder.mViewButton与文字按钮控件相关联
v.setTag(holder); //将holder作为v的标签
}
else{
holder=(WordButton) v.getTag();
}
holder.mViewButton.setText(holder.mWordString);
Log.v("getview", holder.mWordString);
return v;
}
}
/*
* 文字数据的传入与更新
*/
public void updataData(ArrayList<WordButton> DataList){
mWordButtonButtomList=DataList; //文字数据传入
Log.v("Up", "ok");
Log.v("up1",mWordButtonButtomList.get(0).mWordString);
//更新数据
setAdapter(mAdapter); //数据更新
}
}
老师,怎么破啊