Custom Adapter not working for the listview from Parse.com

I am trying to create an android application using a database from Parse.com. I am using a custom adapter to create a listview. I don’t find any errors with the code and yet the listeview is not showing up. Nothing there in the logcat as well. Just the listview does not show up.

    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();
            }

        }
    });

This is the activity where I am invoking the listview.

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;
 }
}

And this is the custom adapter. There are no null pointer exceptions showing up in the logcat. I can’t determine why the listview is not getting populated.

Answer

Try this;

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

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

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

Leave a Reply

Your email address will not be published. Required fields are marked *