求解!为什么运行后模拟器一片空白~ 代码附上了~
MyAdapter.java
public class MyAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private List<Bean> mDatas;
public MyAdapter(Context context,List<Bean> datas) {
mInflater = LayoutInflater.from(context);
mDatas = datas;
}
@Override
public int getCount() {
return mDatas.size();
}
@Override
public Object getItem(int position) {
return mDatas.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if(convertView == null){
convertView = mInflater.inflate(R.layout.item_listview,parent,false);
holder = new ViewHolder();
holder.mTitle = (TextView)convertView.findViewById(R.id.id_title);
holder.mDesc = (TextView)convertView.findViewById(R.id.id_desc);
holder.mTime = (TextView)convertView.findViewById(R.id.id_time);
holder.mPhone = (TextView)convertView.findViewById(R.id.id_phone);
convertView.setTag(holder);
}else{
holder = (ViewHolder)convertView.getTag();
}
Bean bean = mDatas.get(position);
holder.mTitle.setText(bean.getTitle());
holder.mDesc.setText(bean.getDesc());
holder.mTime.setText(bean.getTime());
holder.mPhone.setText(bean.getPhone());
return convertView;
}
private class ViewHolder{
TextView mTitle;
TextView mDesc;
TextView mTime;
TextView mPhone;
}
MainActivity.java
public class MainActivity extends Activity {
private ListView mListView;
private List<Bean> mDatas;
private MyAdapter myAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initDatas();
initView();
}
private void initView() {
mListView = (ListView)findViewById(R.id.id_listview);
mListView.setAdapter(myAdapter);
}
private void initDatas() {
mDatas = new ArrayList<Bean>();
Bean bean = new Bean("Android新技能1",
"Android-打造万能的ListView和GridView适配器",
"2015-10-12", "10086");
mDatas.add(bean);
bean = new Bean("Android新技能2",
"Android-打造万能的ListView和GridView适配器",
"2015-10-12", "10086");
mDatas.add(bean);
bean = new Bean("Android新技能3",
"Android-打造万能的ListView和GridView适配器",
"2015-10-12", "10086");
mDatas.add(bean);
bean = new Bean("Android新技能4",
"Android-打造万能的ListView和GridView适配器",
"2015-10-12", "10086");
mDatas.add(bean);
bean = new Bean("Android新技能5",
"Android-打造万能的ListView和GridView适配器",
"2015-10-12", "10086");
mDatas.add(bean);
myAdapter = new MyAdapter(this,mDatas);
}