RecyclerView, вызывающий в диалоге оповещений, я попытался установить ширину MATCH_PARENT
во время выполнения в onCreateView
в классе адаптера.
if (binding.root.getLayoutParams ().width == RecyclerView.LayoutParams.MATCH_PARENT)
binding.root.getLayoutParams ().width = parent.getWidth ()
Попытка вызова внутри в onCreateView
, но при этом пространство оставалось вертикально.Я перепробовал все возможные комбинации, которые есть на SO, но ничего не работает.
private fun initDialog() {
if (mAlertDialog == null) {
val mBuilder = AlertDialog.Builder(this)
val view1 = layoutInflater.inflate(R.layout.select_itinerary_dialog, null, false)
val mRecyclerView = view1.findViewById<RecyclerView>(R.id.mRecyclerView)
mRecyclerView?.adapter = SelectItineraryAdapter(this@AddItineraryActivity)
val llm = LinearLayoutManager(this@AddItineraryActivity)
// llm.isAutoMeasureEnabled = false
mRecyclerView?.layoutManager = llm
//mRecyclerView?.layoutManager = LinearLayoutManager(this@AddItineraryActivity)
mCheckBoxSelectAll = view1.findViewById<CheckBox>(R.id.checkSelctAll)
mCheckBoxSelectAll?.setOnCheckedChangeListener { _, b ->
if (!fromBroadcastReceiver) {
for (item in mItinerarylistResponse?.data?.itinerary!!) {
item?.isSelected = b
}
mRecyclerView?.adapter!!.notifyDataSetChanged()
}
fromBroadcastReceiver = false
}
view1.findViewById<AppCompatButton>(R.id.clearItinerary).setOnClickListener {
mAlertDialog!!.dismiss()
}
view1.findViewById<AppCompatButton>(R.id.doneItinerary).setOnClickListener {
try {
for (item in mItinerarylistResponse?.data?.itinerary!!) {
viewContainer.visibility = View.VISIBLE
if (item!!.item == "Wake Up") {
if (item.isSelected) {
wakeUpTimeTV.visibility = View.VISIBLE
wakeUpTimeLay.visibility = View.VISIBLE
} else {
wakeUpTimeTV.visibility = View.GONE
wakeUpTimeLay.visibility = View.GONE }
}
}
} catch (e: Exception) {
}
mAlertDialog!!.dismiss()
}
mBuilder.setView(view1)
mAlertDialog = mBuilder.create()
mAlertDialog?.window?.setBackgroundDrawableResource(android.R.color.transparent)
// mAlertDialog?.setView(view1)
}
}
Адаптер
class SelectItineraryAdapter(val contecx: AddItineraryActivity) : RecyclerView.Adapter<SelectItineraryAdapter.MyHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyHolder {
val binding = DataBindingUtil.inflate<RowItemItinararyBinding>(LayoutInflater.from(contecx), R.layout.row_item_itinarary, parent, false)
// val v= LayoutInflater.from(contecx).inflate(LayoutInflater.from(contecx), R.layout.row_item_itinarary, parent, false)
/* if (binding.root.getLayoutParams ().width == RecyclerView.LayoutParams.MATCH_PARENT)
binding.root.getLayoutParams ().width = parent.getWidth ()*/
val dd = MyHolder(binding)
return dd
}
override fun getItemCount(): Int {
return mItinerarylistResponse?.data?.itinerary!!.size
}
@SuppressLint("ClickableViewAccessibility")
override fun onBindViewHolder(holder: MyHolder, position: Int) {
holder.v.itinararyname.text = mItinerarylistResponse?.data?.itinerary!![position]?.item
holder.v.markReadCheck.setOnCheckedChangeListener { _, isChecked ->
mItinerarylistResponse?.data?.itinerary!![position]!!.isSelected = isChecked
val receiverIntentDetail = Intent()
receiverIntentDetail.action = isitinerarySelected
holder.v.markReadCheck.context.sendBroadcast(receiverIntentDetail)
}
holder.v.detailLat.setOnTouchListener { view, motionEvent ->
when (motionEvent.action) {
MotionEvent.ACTION_DOWN -> {
com.socrpro.utils.error("ACTION_DOWN")
}
MotionEvent.ACTION_UP -> {
// if (itinerary[position].readStatus == 0) {
holder.v.markReadCheck.performClick()
// }
com.socrpro.utils.error("ACTION_UP")
}
MotionEvent.ACTION_MOVE -> {
com.socrpro.utils.error("ACTION_MOVE")
}
}
true
}
holder.v.markReadCheck.isChecked = mItinerarylistResponse?.data?.itinerary!![position]!!.isSelected
}
class MyHolder(val v: RowItemItinararyBinding) : RecyclerView.ViewHolder(v.root)
}
Row_item
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:id="@+id/detailLat" android:layout_width="match_parent" android:layout_height="wrap_content"
android:clickable="true" android:orientation="vertical">
<LinearLayout android:id="@+id/readornot" android:layout_width="match_parent"
android:layout_height="@dimen/_25sdp" android:background="@color/white"
android:gravity="center_vertical" android:orientation="horizontal"
android:paddingTop="@dimen/_5sdp" android:paddingBottom="@dimen/_5sdp">
<CheckBox android:id="@+id/markReadCheck" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:button="@drawable/custom_checkbox" android:layoutDirection="rtl"
android:text="" />
<TextView android:id="@+id/itinararyname" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/_2sdp" android:layout_marginEnd="@dimen/_5sdp"
android:layout_weight="1" android:singleLine="true"
android:text="dfgdgfdggfdg" android:textColor="@color/colorPrimary"
android:textSize="@dimen/_10sdp" />
</LinearLayout>
<View android:layout_width="match_parent" android:layout_height=".5dp"
android:layout_alignBottom="@+id/readornot" android:background="@color/linecolorcc" />
</RelativeLayout>
</layout>