【发布时间】:2019-04-14 07:44:28
【问题描述】:
我目前正在关注一个关于 RecyclerView 的教程,它是用 java “编写”的。 现在我正在尝试基本上学习本教程并在 Kotlin 中编写代码。 我现在想从单独创建的类“RecyclerViewAdapter”中访问 layout_listitem.xml(它基本上只是描述了 recyclerview 中单个元素的结构)中的视图。
这实际上不应该与单独的 xml 文件一起工作还是这是一个实际问题?
PS:我也试过用 “import kotlinx.android.synthetic.main.layout_listitem.*”,但这似乎也不起作用。
RecyclerViewAdapter
package com.gmail.mynamepackage.recyclerviewdemo
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
class RecyclerViewAdapter : RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
//In this complete class i am not able to access the views directly
}
layout_listitem.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp"
android:id="@+id/parentLayout">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:id="@+id/image"
android:src="@mipmap/ic_launcher"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Canada"
want to acc: android:id="@+id/image_name"
android:layout_toRightOf="@+id/image"
android:textColor="#000"
android:layout_centerVertical="true"
android:layout_marginLeft="58dp"
android:textSize="17sp"
/>
</RelativeLayout>
【问题讨论】:
标签: android kotlin android-recyclerview android-view kotlin-extension