我正在使用Fragment来显示列表。 ListAdapter使用Baseadapter。它返回的getcount大于0,但仍未调用getview()方法。baseadapter的getview()方法在片段中未调用
我也被设置在片段适配器,并呼吁listadapter,如:
mListAdapter = new MyListAdapter(getActivity(), data, enum);
sList.setAdapter(mListAdapter);
mListAdapter.notifyDataSetChanged();
适配器被称为没有问题,GetCount()
又称但 GetView()
不会被调用。
ListAdapter:
public class MyListAdapter extends BaseAdapter {
private ArrayList<WatchVO> data;
private static LayoutInflater inflater;
private Context mcontext;
private ENUM enum;
public String TAG = "MyListAdapter";
public MyListAdapter(Context context, ArrayList<WatchVO> data,
ENUM enum) {
// super(context,0,data);
this.mcontext = context;
this.data = data;
this.enum = enum;
inflater = (LayoutInflater) mcontext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() { Log.d(TAG,"count"+data.size());
if (data.size()<=0)
return 1;
return data.size();
}
@Override
public Object getItem(int position) {
Log.d(TAG,"getitem"+data.get(position));
return data.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@SuppressLint("NewApi")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if(convertView==null) {
holder = new ViewHolder();
Log.d(TAG,""+parent +"pos" + position);
convertView = inflater.inflate(R.layout.single_row_scripts,parent,false);
holder.tableRow = (TableRow) convertView.findViewById(R.id.table_row_item);
holder.priceChangeContainer = (LinearLayout) convertView.findViewById(R.id.color_container_red_green);
holder.sName = (TextView) convertView.findViewById(R.id.sName);
holder.sPrice = (TextView) convertView.findViewById(R.id.sMRP);
holder.sPriceChange = (TextView) convertView.findViewById(R.id.sPrice);
holder.sPricePercentageChange = (TextView) convertView.findViewById(R.id.sPriceChange);
holder.sVolume = (TextView) convertView.findViewById(R.id.sVolume);
holder.sName.setText(data.get(position).getSName());
holder.sPrice.setText(data.get(position).getSMRP());
holder.sPriceChange.setText(data.get(position).getSChange());
holder.sPricePercentageChange.setText(data.get(position).getSPercentageChange());
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
return convertView;
}
public static class ViewHolder {
public TextView sName, sPrice, sPriceChange, sPricePercentageChange, sVolume;
public LinearLayout priceChangeContainer;
public TableRow tableRow;
}
}
嘿..它会为一次通话。它不会在晚些时候要求。因为您每次检查convertView == null。一旦您将视图分配给convertview,则convertview不为null。所以你的情况不会奏效。 –