更新android studio后RecyclerView不显示列表中的所有项目

我想在我的 RecyclerView 中显示这些项目,但它根本不显示,我看不到错误。也许你们可以帮助我。我的代码在这里:


活动:


public class ProductsViewActivity extends AppCompatActivity {

    private RecyclerView productView;

    private ArrayList<Product> lstProduct;

    private RecyclerView.LayoutManager layoutManager;

    private ProductAdapter productAdapter;


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_products_view);

        if (android.os.Build.VERSION.SDK_INT > 9) {

            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

            StrictMode.setThreadPolicy(policy);

        }

        lstProduct = new ArrayList<>();

        lstProduct.add(new Product(1, "Product 1", "This is good product", "https://www.dollargeneral.com/media/catalog/product/cache/image/700x700/e9c3970ab036de70892d86c6d221abfe/2/0/20706301_kibbles_nbitsbacon_steakflavordrydogfood3.6lb_main.jpg", 34.78));

        lstProduct.add(new Product(2, "Product 2", "This is good product", "https://www.iams.com/images/default-source/product-packshot/dog/iams-proactive-health-smart-puppy-large-breed-dog-food.png?sfvrsn=6", 34.78));

        productView = findViewById(R.id.productView);

        loadProductView();

    }


    private void loadProductView() {

        productView.setHasFixedSize(true);


        layoutManager = new LinearLayoutManager(this);

        productView.setLayoutManager(layoutManager);


        productAdapter = new ProductAdapter(lstProduct);

        productView.setAdapter(productAdapter);

        Log.e("Product view", "Size ======>" + productAdapter.getItemCount());

    }

}


弑天下
浏览 224回答 2
2回答

哔哔one

检查“product_list_item”根 ViewGroup 宽度是否为:wrap_content not match_parent。布局/product_list_item.xml:<LinearLayout&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;android:layout_height="wrap_content"当然,如果它是 match_parent,你会遇到这个问题。

心有法竹

看起来一切都很好,但有一件事试图使缓存无效并重新启动你的android工作室文件 > 使缓存无效/重新启动希望如此,它会工作
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java