我正在使用recyclerview。我收到此错误add(... OmborActivty)在列表中无法应用于(... OmborModel)。在下面的部分中,我使用了此代码:Recyc_Adapter_Ombor myAdapter = new Recyc_Adapter_Ombor(this,lstOmbor);。有人说使用getAcivity()或getContext()。但是,当我键入上面建议的方法而不是上面的方法时,得到的是“无法解析方法”。
这是我的代码:
package com.example.ganz.afex_with_default_navigation;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import com.example.ganz.afex_with_default_navigation.adapters.Recyc_Adapter_Ombor;
import com.example.ganz.afex_with_default_navigation.models.Ombor_Model;
import java.util.ArrayList;
import java.util.List;
public class OmborActivity extends AppCompatActivity {
List<OmborActivity> lstOmbor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ombor);
lstOmbor = new ArrayList<>();
lstOmbor.add(new Ombor_Model("Zara", "Qizlar uchun shim", "85 ming so'm", R.drawable.img));
lstOmbor.add(new Ombor_Model("Gucci", "Qizlar uchun triko", "189 ming so'm", R.drawable.img));
lstOmbor.add(new Ombor_Model("Gucci", "Qizlar uchun ko'ylak", "100 ming so'm", R.drawable.img));
lstOmbor.add(new Ombor_Model("Versaci", "Qizlar uchun ko'ylak", "120 ming so'm", R.drawable.img));
RecyclerView myrv = (RecyclerView) findViewById(R.id.recycler_ombor);
Recyc_Adapter_Ombor myAdapter = new Recyc_Adapter_Ombor(this, lstOmbor);
myrv.setLayoutManager(new GridLayoutManager(this, 2));
myrv.setAdapter(myAdapter);
}
}
最佳答案
将List<OmborActivity> lstOmbor;
更改为List<Ombor_Model> lstOmbor;
关于java - 列表中的add(...)不能应用于(...),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50679105/