Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法使用我的POJO解析构造函数ArrayAdapter_Java_Android_Android Studio - Fatal编程技术网

Java 无法使用我的POJO解析构造函数ArrayAdapter

Java 无法使用我的POJO解析构造函数ArrayAdapter,java,android,android-studio,Java,Android,Android Studio,我正在尝试创建我的ArrayAdapter,以便单击列表中的一个元素并获得所有结果。这就是我正在做的 public ArrayAdapter<UserPojo> getAdapter(Context adapterContext) { return new ArrayAdapter<UserPojo>(adapterContext,android.R.layout.simple_list_item_1,getmList()); } public LinkedL

我正在尝试创建我的ArrayAdapter,以便单击列表中的一个元素并获得所有结果。这就是我正在做的

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;
}
在这里,我使用它来点击一个元素并得到结果

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

}
我面临的问题是在这条线上

新的 ArrayAdapteradapterContext,android.R.layout.simple_list_item_1,getmList

这么说

无法解析构造函数 'ArrayAdapterandroid.content.Context,int,LinkedList'


ArrayAdapter类需要创建与super匹配的构造函数。 要创建YourAdapter,请执行以下操作:

YourAdapter yourAdapter = new YourAdapter(getActivity(), listYourPojo);
您的适配器类:

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

如果列表yourpojo是静态的,则只需按您的意图传递索引。

您需要为此创建自定义ArrayAdapter。您是否重新声明了另一个名为ArrayAdapter???的类?因为您调用了方法getmList,该方法返回的mList与该方法没有任何关系。mList来自哪里?您必须将任何类型的集合传递给arrayadapter.private LinkedList mList=新LinkedList;这就是它的来源。您是否为arrayadapter或另一个名为arrayadapter的customclass使用了正确的导入。因为arrayadapter有一个包含您调用的方法的构造函数,所以我这样做了,但是当我尝试向列表中添加值时,我在这行mList.adduserPojo.getEmail中出现了一个错误;因为getEmail是一个字符串,列表的类型是UserPojo。我需要做什么?我不能通过mList.getuserPojo,因为它是一个int,而mList的类型是UserPojosorry:int index=mList.indexOfuserPojo;UserPojo UserPojo=mList.getindex;userPojo.setEmail;mList.setindex,userPojo;另外,set用于替换列表中特定索引中的现有值。我需要向列表中添加元素,而不是替换userPojo userPojo=newuserpojo;userPojo.setEmail;mList.adduserPojo;