0

I am trying to retrieve data from parse,therefore I need to make a custom adapter for the listview but its not working,I created a custom adapter but the listview is not showing and I can't figure out what is the problem. I am getting no errors or crashes so I can't point the exact problem.

This is what I have done:

The adapter:

public class MyListView extends BaseAdapter {

    private final ArrayList<HashMap<String, String>> contentList;
    private static LayoutInflater inflater = null;

    public MyListView(Activity a, ArrayList<HashMap<String, String>> contentForList) {
        this.contentList = contentForList;
        inflater = (LayoutInflater) a.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public int getCount() {
        return contentList.size();
    }

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

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

    public View getView(int position, View convertView, ViewGroup parent) {
        View vi = convertView;
        if (convertView == null)
            vi = inflater.inflate(R.layout.mylist, null);

        ImageView logo = (ImageView) vi.findViewById(R.id.icon); // title
        TextView titleText = (TextView) vi.findViewById(R.id.title); // artist name
        TextView subtitleText = (TextView) vi.findViewById(R.id.subtitle);


        HashMap<String, String> info = new HashMap<String, String>();
        info = contentList.get(position);
        String title = (String) info.get("businessname");
        String peopleinBusiness = (String) info.get("peopleinbusiness");

        // Setting all values in listview
        titleText.setText(title);
        subtitleText.setText(peopleinBusiness);
//        Bitmap bmp = (Bitmap) info.get("photo");
//        logo.setImageBitmap(bmp);

        return vi;
    }
}

listView XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/icon"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:padding="5dp" />

    <LinearLayout android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Medium Text"
            android:textStyle="bold"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="5dp"
            android:padding="2dp"
            android:textColor="#4d4d4d" />
        <TextView
            android:id="@+id/subtitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:layout_marginLeft="10dp"/>
    </LinearLayout>
</LinearLayout>

MainActivity:

ArrayList<HashMap<String,String>> feedData = new ArrayList<>();

ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
query.orderByDescending("createdAt");
query.setLimit(20);

query.findInBackground(new FindCallback<ParseObject>() {
    @Override
    public void done(List<ParseObject> objects, ParseException e) {

        if (e == null){

            for (ParseObject feed : objects){


                HashMap<String, String> PlacesInfo = new HashMap<>();
                PlacesInfo.put("username",feed.getString("username"));
                PlacesInfo.put("worthcomming",feed.getString("worthcomming"));
                PlacesInfo.put("businessname",feed.getString("BusinessName"));
                PlacesInfo.put("peopleinbusiness",feed.getString("PeopleInBusiness"));

                feedData.add(PlacesInfo);
            }



            MyListView listview = new MyListView(FeedActivity.this,feedData);
            feedListView.setAdapter(listview);
            listview.notifyDataSetChanged();
        }else{
            Log.e("findinBackground","Failed");
            e.printStackTrace();
        }

    }
});

Thank you !!

HoLoGram
  • 167
  • 10
  • If nothing is shown for a ListView, first is to check the size() of data list, so add Log to check **objects.size()** and **feedData.size()** inside query **done()**. If data list is not empty, then check if adapter is called, so add Log inside **getView()**. If adapter is called, then problem may be either layout of Activity or ListView. On the other hand, no need to make HashMaps, directly pass List into the adapter (https://stackoverflow.com/questions/42050789/android-adding-searchview-inside-a-listview-with-custom-adaptor/42216765#42216765). – i_A_mok May 08 '21 at 03:44
  • Hey @i_A_mok thank you for your reply ! I just logged the data you specified and there is no data in it.When I log them into the for loop its not logging anything but if I log it after it says 0. I don't understand why because "User" folder is exist in parse. ( Parse Photo - https://ibb.co/vDVrzfm ) – HoLoGram May 09 '21 at 18:39
  • I don't have much experience on Parse Platform, cannot tell where is the problem. May be try **ParseUser**, e.g. `ParseQuery userQuery = ParseUser.getQuery(); userQuery.findInBackground(new FindCallback() { void done(List results, ParseException e) {......}` instead of **ParseObject**. – i_A_mok May 10 '21 at 03:28

1 Answers1

0

I can't believe I spend so much time only to figure out I was missing a " _ " .

I changed this:

ParseQuery<ParseObject> query = ParseQuery.getQuery("User");

To this:

ParseQuery<ParseObject> query = ParseQuery.getQuery("_User");

Thank everyone !

HoLoGram
  • 167
  • 10