I am using an adapter in ListView
. The problem is no row is displayed and no exception raised, but there are 10 records which I am sending to adapter. When I debug it I don't know why getView()
is not executing
I have set adapter like this
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) );
and my adapter is like this:
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;
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…