我正在使用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。所以你的情況不會奏效。 –