gpt4 book ai didi

java - 自定义适配器不适用于 Parse.com 的 ListView

转载 作者:行者123 更新时间:2023-11-29 20:31:19 25 4
gpt4 key购买 nike

我正在尝试使用来自 Parse.com 的数据库创建一个 android 应用程序。我正在使用自定义适配器来创建 ListView 。我没有发现代码有任何错误,但 listeview 没有显示。 logcat 中也没有任何内容。只是 ListView 不显示。

    lv = (ListView)findViewById(R.id.listView);
mProgress = (ProgressBar)findViewById(R.id.check_progress);
mProgress.setVisibility(View.VISIBLE);

ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Sellers");
query.orderByAscending("Name");
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> parseObjects, ParseException e) {
if (e == null) {
studentsList = new ArrayList<Sellers>();
for (ParseObject ob : parseObjects) {
s = new Sellers();

s.setName(ob.getString("Name").toString());
s.setAddress1(ob.getString("Address1").toString());
s.setAddress2(ob.getString("Address2").toString());
s.setShopName(ob.getString("ShopName").toString());
s.setEmail(ob.getString("Email").toString());
s.setPhone(ob.getString("Phone").toString());
s.setZipcode(ob.getString("Zipcode").toString());

studentsList.add(s);
}
adapter = new ListviewAdapter(CheckStatus.this, studentsList);
lv.setAdapter(adapter);
mProgress.setVisibility(View.GONE);


} else {
mProgress.setVisibility(View.GONE);
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}

}
});

这是我调用 ListView 的 Activity 。

public class ListviewAdapter extends BaseAdapter{

private final static String TAG = ListviewAdapter.class.getSimpleName();

private Context activity;
private LayoutInflater inflater = null;
private List<Sellers> sellers;
int layout;

public ListviewAdapter(Context activity, List<Sellers> sellers) {


this.activity = activity;
this.sellers = sellers;
inflater = LayoutInflater.from(activity);
}

@Override
public int getCount() {
return 0;
}

@Override
public Object getItem(int position) {
return null;
}

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

public class ViewHolder {
TextView name ;
TextView shop ;
TextView address1 ;
TextView address2;
TextView phone;
TextView email;
RelativeLayout rl;
}

@Override
public View getView(int position, View view, ViewGroup parent) {
View v =view;
ViewHolder holder = new ViewHolder();

if (view == null) {
LayoutInflater li = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = li.inflate(R.layout.list_item_layout,null);
holder.name = (TextView)v.findViewById(R.id.seller_name);
holder.shop = (TextView)v.findViewById(R.id.shop_name);
holder.address1 = (TextView)v.findViewById(R.id.address1);
holder.address2 = (TextView)v.findViewById(R.id.address2);
holder.phone = (TextView)v.findViewById(R.id.phone);
holder.email = (TextView)v.findViewById(R.id.emailID);
v.setTag(holder);
} else {
holder = (ViewHolder) v.getTag();
}

Sellers s = sellers.get(position);


// String a = s.Name;
// Log.d(TAG, a);
holder.name.setText(s.getName());
holder.shop.setText(s.getShopName());
holder.address1.setText(s.getAddress1());
holder.address2.setText(s.getAddress2());
holder.phone.setText(s.getPhone());
holder.email.setText(s.getEmail());

Log.d("CustomAdapter.class", "CustomAdapter");

// imageView.setImageDrawable(s.getPic());
return v;
}
}

这是自定义适配器。 logcat 中没有出现空指针异常。我无法确定为什么 ListView 没有被填充。

最佳答案

试试这个;

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

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

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

关于java - 自定义适配器不适用于 Parse.com 的 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31904019/

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