[犯过的错误] 2019年3月18日-使用RecyclerView

出现了一个界面只有一个子项的情况,这是为什么呢?

因为子项的布局中,把子项的root element布局高度设为了match_parent。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    就是这里:
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/recycler_item_img"
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:layout_weight="1"
        android:scaleType="fitXY"/>


    <TextView
        android:id="@+id/recycler_item_text"
        android:layout_weight="5"
        android:layout_width="0dp"
        android:layout_height="50dp" />



</LinearLayout>

从非Activity中启动activity

第一个是flag
第二个是context如何初始化

        viewHolder.textView.setOnClickListener(v -> {
            //没有context初始化的时候,编译期不报错,但是运行期报错
            context = v.getContext();
//            Activity activity = (Activity) v.getContext();
            Intent intent = new Intent(context, ItemContext_activity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
        });

使用ArrayList

一定要在声明的时候new,把地址空间给分配了
不然是没有办法进行list.add之类的操作的

使用databinding时

在尝试使用databind的时候,把item实体类对象的变量变成了ObservableField
然后再初始化RecyclerView的时候出错了因为:
Observable也一定要先new才能用的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值