0

I'm trying to create my ArrayAdapter in order to click an element in my list and get it with all the results. This is what I'm doing.

public ArrayAdapter<UserPojo> getAdapter(Context adapterContext) {
    return new ArrayAdapter<UserPojo>(adapterContext,android.R.layout.simple_list_item_1,getmList());
}


public LinkedList<String> getmList() {

    mQueryDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            fetchData(dataSnapshot);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

    return mList;
}

And here is where I use it in order to click an element and get the results of it

public void clickListItems(ListView listView,final DatabaseReference mRootDatabase) {
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            Toast.makeText(mContext, "Clicked: " + getmList().get(position), Toast.LENGTH_SHORT).show();
            userPojo = getAdapter(mContext).getItem(position);
            Intent intent = new Intent(mContext, UserEdit.class);
            intent.putExtra("uid", mRootDatabase.getKey());
            intent.putExtra("Name",getAdapter(mContext).getItem(position).getName());
            intent.putExtra("Email", getAdapter(mContext).getItem(position).getEmail());
            intent.putExtra("Pay", getAdapter(mContext).getItem(position).getPay());
            intent.putExtra("LastCon", getAdapter(mContext).getItem(position).getLastCon());
            intent.putExtra("FirstCon", getAdapter(mContext).getItem(position).getFirstCon();
            mContext.startActivity(intent);
        }
    });

}

The problem I'm facing is at this line

new ArrayAdapter(adapterContext,android.R.layout.simple_list_item_1,getmList());

Saying this

Cannot resolve constructor 'ArrayAdapter(android.content.Context,int,LinkedList'

Guillaume S
  • 1,462
  • 2
  • 19
  • 31
Todd
  • 179
  • 15
  • You need to create custom `ArrayAdapter` for that https://stackoverflow.com/questions/8166497/custom-adapter-for-list-view – AskNilesh Aug 30 '18 at 12:25
  • did u redeclare another class with name ArrayAdapter??? – Venkata Narayana Aug 30 '18 at 12:29
  • because you have called method getmList() which returns mList which don't have any relation with the method. where does mList come from? you have to pass any kind of collection to your arrayadapter. – Jay Mungara Aug 30 '18 at 12:49
  • private LinkedList mList = new LinkedList<>(); thats where it come from – Todd Aug 30 '18 at 12:52
  • did u use the right import for arrayadapter or another customclass called array adapter. because arrayadapter has a constructor with the methods you are calling – Venkata Narayana Aug 30 '18 at 13:27
  • I have made my own and checked my imports – Todd Aug 30 '18 at 13:55

1 Answers1

1

ArrayAdapter class needs create constructor matching super. To create your YourAdapter:

YourAdapter yourAdapter = new YourAdapter(getActivity(), listYourPojo);

YourAdapter class:

public class YourAdapter extends ArrayAdapter<YourPojo> {

    public static List<YourPojo> listYourPojo = new ArrayList<>();
    Context context;

    public YourAdapter(Context context, List<YourPojo> listYourPojo) {
        super(context, 0, listYourPojo);
        this.context = context;
        this.listYourPojo  = listYourPojo;
    }
}

If your List listYourPojo is static, you only need pass the index in your intent.