您好,我是Kotlin的新手,我一直面临一个非常奇怪的问题。我有一个填充了一些子布局的简单ListView! 我的XML的ListView标记为:
<ListView
android:id="@+id/invoicesList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@null"
android:dividerHeight="0dp"/>
我的适配器是:
class InvoicesListAdapter(context: Context, activity: Activity, resource: Int, list: ArrayList<InvoicesListModel>) : ArrayAdapter<InvoicesListModel>(context, resource, list) {
var list: ArrayList<InvoicesListModel> = list
var activity: Activity? = null
init {
this.activity = activity
}
private class ViewHolder(row: View?) {
var serviceName: BakcellTextViewNormal? = null
var endirimValue: BakcellTextViewNormal? = null
var miqdarValue: BakcellTextViewNormal? = null
var vahidValue: BakcellTextViewNormal? = null
var mablaqValue: BakcellTextViewNormal? = null
var camiValue: BakcellTextViewNormal? = null
init {
this.serviceName = row?.findViewById(R.id.serviceValue)
this.endirimValue = row?.findViewById(R.id.endirimValue)
this.miqdarValue = row?.findViewById(R.id.miqdarValue)
this.vahidValue = row?.findViewById(R.id.vahidValue)
this.mablaqValue = row?.findViewById(R.id.mablaqValue)
this.camiValue = row?.findViewById(R.id.camiValue)
}//init ends
}// class ViewHolder ends
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val view: View?
val viewHolder: ViewHolder
if (convertView == null) {
val inflater = context?.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
view = inflater.inflate(R.layout.invoices_list_layout, null)
viewHolder = ViewHolder(view)
view?.tag = viewHolder
} else {
view = convertView
viewHolder = view.tag as ViewHolder
}
var listModel = getItem(position)
viewHolder.serviceName!!.text=listModel.serviceName
viewHolder.miqdarValue!!.text=listModel.miqdarValue
viewHolder.vahidValue!!.text=listModel.vahidValue
viewHolder.mablaqValue!!.text=listModel.mablaqValue
viewHolder.endirimValue!!.text=listModel.endirimValue
viewHolder.camiValue!!.text=listModel.camiValue
//send arrow click
return view as View
}//getview ends
}//class ends
我的适配器/ ListView项目布局为:
<?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">
<!--nested container-->
<RelativeLayout
android:id="@+id/ripple"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/_10sdp"
android:paddingTop="@dimen/_10sdp">
<RelativeLayout
android:id="@+id/childLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/_20sdp"
android:layout_marginRight="@dimen/_20sdp"
android:orientation="horizontal">
<!--col1-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4.2">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.es.b2bbakcell.widgets.textwidgets.BakcellTextViewNormal
android:id="@+id/serviceValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Blackberry Service"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/_10ssp"/>
</RelativeLayout>
</LinearLayout>
<!--col2-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.es.b2bbakcell.widgets.textwidgets.BakcellTextViewNormal
android:id="@+id/miqdarValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="12345"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/_10ssp"/>
</RelativeLayout>
</LinearLayout>
<!--col3-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4.9">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.es.b2bbakcell.widgets.textwidgets.BakcellTextViewNormal
android:id="@+id/vahidValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="saat:den:san"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/_10ssp"/>
</RelativeLayout>
</LinearLayout>
<!--col4-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.es.b2bbakcell.widgets.textwidgets.BakcellTextViewNormal
android:id="@+id/mablaqValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="98.2"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/_10ssp"/>
</RelativeLayout>
</LinearLayout>
<!--col5-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3.3">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.es.b2bbakcell.widgets.textwidgets.BakcellTextViewNormal
android:id="@+id/endirimValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="0.0"
android:textColor="@color/colorTextBlack"
android:textSize="@dimen/_10ssp"/>
</RelativeLayout>
</LinearLayout>
<!--col6-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.es.b2bbakcell.widgets.textwidgets.BakcellTextViewNormal
android:id="@+id/camiValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="1125.7"
android:textColor="@color/colorTextBlack"
android:textSize="@dimen/_10ssp"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<!--//nested container-->
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/ripple"
android:layout_marginLeft="@dimen/_45sdp"
android:layout_marginRight="@dimen/_45sdp"
android:background="@color/colorSeperator"></View>
</RelativeLayout>
问题是当我使用id = ripple进入相对布局时,我想显示波纹! 我知道我可以设置:
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
在所需的布局上! 但是,每当我在相对布局上使用id = ripple注册任何点击侦听器时,它都会停止显示涟漪效应!
我正在具有Android 5.0 Lollipop的LG G3上进行测试,并且希望具有Android 19+版本的Android设备显示出涟漪效应。
我必须使用
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
以显示涟漪效应,有人可以帮我确定我做错了什么吗?预先感谢!
答案 0 :(得分:0)
尝试?attr/selectableItemBackgroundBorderless