gpt4 book ai didi

android - 文本未在 Baseadapter 中设置

转载 作者:行者123 更新时间:2023-11-30 01:40:42 24 4
gpt4 key购买 nike

我正在关注 this实现 EndlessScrolllistview 的示例,当我运行我的应用程序时应用程序崩溃并给出以下错误,任何帮助将不胜感激,谢谢

这是我的适配器类

public class EndlessAdapter extends BaseAdapter {

//private List<String> itemList;
private Context ctx;
private int layoutId;


private ArrayList<HashMap<String, String>> listData;
//private AQuery aQuery;
String rup = "\u20B9";
//private ArrayList<String> usersizesArrayList;

private static final String TAG_NAME = "name";
private static final String TAG_IMAGE = "img_url";
private static final String TAG_PRICE = "price";
private static final String TAG_ID_PRODUCT = "id_product";
/*public EndlessAdapter(Context ctx, List<String> itemList, int layoutId) {
super(ctx, layoutId, itemList);
this.itemList = itemList;
this.ctx = ctx;
this.layoutId = layoutId;
}*/

public EndlessAdapter(Context ctx, ArrayList<HashMap<String, String>> listData) {
this.ctx = ctx;
this.listData = listData;
//aQuery = new AQuery(this.context);
}

@Override
public int getCount() {
return listData.size() ;
}

@Override
public Object getItem(int position) {
return listData.get(position);
}

@Override
public long getItemId(int position) {
return position;
}

/*@Override
public View getView(int position, View convertView, ViewGroup parent) {
View result = convertView;

if (result == null) {
LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
result = inflater.inflate(layoutId, parent, false);
}

// We should use class holder pattern
TextView tv = (TextView) result.findViewById(R.id.txt1);
//tv.setText(itemList.get(position));
*/

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();

convertView = LayoutInflater.from(ctx).inflate(R.layout.row_layout, null);
holder.txtproname = (TextView) convertView.findViewById(R.id.txt1);

} else {
holder = (ViewHolder) convertView.getTag();
}

holder.txtproname.setText(listData.get(position).get(TAG_NAME));
return convertView;

}
class ViewHolder {
public EditText qunatityss;
public TextView bordrsfourth;
public TextView bordrsthird;
public TextView bordrssecond;
public TextView bordrs;
public RadioButton productsizesmall;
public RadioButton productsizemed;
public RadioButton productsizelarge;
public RadioButton productsizexlarge;
public TextView fourthcolor;
public TextView thirdcolor;
public TextView secondcolor;
public ImageView cartview;
TextView txtprice;
ImageView propic;
TextView txtproname;
TextView firstcolor;
Button addtocart;
}

错误

12-31 12:43:52.611: E/AndroidRuntime(6029): FATAL EXCEPTION: main
12-31 12:43:52.611: E/AndroidRuntime(6029): java.lang.NullPointerException
12-31 12:43:52.611: E/AndroidRuntime(6029): at com.survivingwithandroid.endlessadapter.EndlessAdapter.getView(EndlessAdapter.java:109)

第109行是

holder.txtproname.setText(listData.get(position).get(TAG_NAME));

有人能帮忙吗??

最佳答案

您无需将持有者对象声明为最终对象。

public View getView(int position, View convertView, ViewGroup parent) {

ViewHolder holder;

if (convertView == null) {

convertView = LayoutInflater.from(ctx).inflate(R.layout.row_layout, null);

holder = new ViewHolder();

holder.txtproname = (TextView) convertView.findViewById(R.id.txt1);

convertView.setTag(holder);

}

else {

holder = (ViewHolder) convertView.getTag();

}

}

关于android - 文本未在 Baseadapter 中设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34542706/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com