以编程方式更改卡片视图可点击的属性

时间:2017-11-02 04:01:38

标签: android radio-button android-cardview clickable programmatically

如何在运行时将卡片视图可点击属性从true更改为false,例如当" A"选中单选按钮我想显示新项目并可点击虚假,当" B"选中单选按钮我想显示具有不同项目数的新项目,并且可单击为true。 我该如何实现呢? 我试过这个:

    private void setUpDailyRecycleView(List<IWeather> dailyWeathers){

    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.daily_recylceview);
    CardAdapter cardAdapter = new CardAdapter(this, dailyWeathers);
    CardView cardView = (CardView) findViewById(R.id.daily_card);
    cardView.setClickable(true);
    recyclerView.setAdapter(cardAdapter);

    LinearLayoutManager verticalLayoutManger = new LinearLayoutManager(this);
    verticalLayoutManger.setOrientation(LinearLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(verticalLayoutManger);

}

和此:

    private void setUpDailyRecycleView(List<IWeather> dailyWeathers){

    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.daily_recylceview);
    CardAdapter cardAdapter = new CardAdapter(this, dailyWeathers);
    recyclerView.setAdapter(cardAdapter);

    LinearLayoutManager verticalLayoutManger = new LinearLayoutManager(this);
    verticalLayoutManger.setOrientation(LinearLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(verticalLayoutManger);
    CardView cardView = (CardView) findViewById(R.id.daily_card);
    cardView.setClickable(true);

}

但抛出NullPointerException,因为卡视图对象为空。

0 个答案:

没有答案