我在ListView
. 问题是没有显示行并且没有引发异常,但是有 10 条记录要发送到适配器。当我调试它时,我不知道为什么getView()
不执行
我已经设置了这样的适配器
abc = layoutInflater.inflate(R.layout.mainlayoutcontainer, container,false);<br>
mainListView = (ListView)abc.findViewById(R.id.listviewlayout);<br>
mainListView.setAdapter(new myAdapter((Activity)BaseActivity.getContext(), Mydate) );
我的适配器是这样的:
class MyAdapter extends BaseAdapter {
private Context context;
List<students> myObj = null;
public MyAdapter(Context context, List<students> Objects) {
this.context = context;
StudentOnject = Objects;
}
public Context getContext() {
return context;
}
public void setContext(Context context) {
this.context = context;
}
@Override
public int getCount() {
if(StudentOnject == null || StudentOnject.size() == 0){
return 0 ;
}
return StudentOnject.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
try
{
if (StudentOnject != null) {
ViewHolder holder;
User item = StudentOnject.get(position);
if (item != null) {
if (convertView == null) {
convertView = (RelativeLayout) View.inflate(context,
context.getResources().getIdentifier(
"inviteStudents", "layout",
context.getPackageName()), null);
holder = new ViewHolder();
holder.itemRow=convertView.findviewbuid("row");
convertView.setTag(holder);
}else {
holder = (ViewHolder) convertView.getTag();
}
holder.itemRow.setbackground("bla bla bla"); <br>
<br>return convertView;<br>
<br>}
<br>}
return null;<br>
}catch (Exception e) {
return convertView;
}
}
class ViewHolder{
RelativeLayout itemRow;
}
}
}