I have been updating my apps forgot password functionality from Activity to simple custom Alert Dialog. How should I add rounded corners to Dialog window? I have already read multiple tutorials, but none seem to work in my case. I read from somewhere that I should use setBackgroundResources method somewhere, but I'm not sure where.
Kotlin code
// Forgot password textview onClick Listener
binding.tvForgotPassword.setOnClickListener {
// Inflate add_item_dialog.xml custom view
val dialogView = LayoutInflater.from(this).inflate(R.layout.dialog_forgot_password, null)
// Add AlertDialog Builder
val dialogBuilder = AlertDialog.Builder(this)
.setView(dialogView)
// Binding add_item_dialog layout
val dialogBinding = DialogForgotPasswordBinding.bind(dialogView)
// Show Forgot password Dialog
val customAlertDialog = dialogBuilder.show()
dialogBinding.ivCloseDialog.setOnClickListener {
customAlertDialog.dismiss()
}
}
dialog_forgot_password.xml
<androidx.cardview.widget.CardView
android:layout_width="350dp"
android:layout_height="500dp"
app:cardCornerRadius="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="350dp"
android:layout_height="500dp">
<ImageView
android:id="#+id/iv_closeDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.94"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.060000002"
app:srcCompat="#drawable/ic_close" />
<TextView
android:id="#+id/tv_forgotPasswordInfo"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center"
android:textSize="18sp"
android:text="#string/enter_email"
android:textColor="#color/ColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tv_forgotPassword" />
<Button
android:id="#+id/submitBtn"
android:layout_width="200dp"
android:layout_height="50dp"
android:layout_marginBottom="20dp"
android:background="#drawable/button"
android:elevation="4dp"
android:text="#string/submit"
android:textColor="#color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/emailForgot"
app:layout_constraintVertical_bias="1.0" />
<TextView
android:id="#+id/tv_forgotPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="36dp"
android:fontFamily="sans-serif-black"
android:text="#string/forgot_password"
android:textColor="#color/ColorPrimary"
android:textSize="40sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/iv_closeDialog" />
<EditText
android:id="#+id/emailForgot"
android:layout_width="300dp"
android:layout_height="40dp"
android:background="#drawable/rounded_edittext"
android:ems="10"
android:hint="#string/email_address"
android:importantForAutofill="no"
android:inputType="textEmailAddress"
android:paddingStart="15dp"
android:textColorHint="#color/ColorPrimary"
app:layout_constraintBottom_toTopOf="#+id/submitBtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tv_forgotPasswordInfo"
app:layout_constraintVertical_bias="1.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
Rounded_framelayout.xml
<solid android:color="#FFFFFF"/>
<padding android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp"/>
<corners android:radius="20dp" />
Please take a look at this guide for how to customize dialogs.
In short, you need to create a dialog like normal, but set the background resource before you show it:
val builder = AlertDialog.Builder(context)
builder.setView(R.layout.item_dialog)
val dialog = builder.create()
dialog.window?.decorView?.setBackgroundResource(R.drawable.dialog_background) // setting the background
dialog.show()
where dialog_background is defined like so:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="16dp" />
<solid android:color="?android:colorBackground" />
</shape>
TRY THIS:
class your_kotlin_filename :DialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
dialog!!.window?.setBackgroundDrawableResource(R.drawable.Rounded_framelayout);
return inflater.inflate(R.layout.dialog_forgot_password, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
............your code for forget password...........
}
override fun onStart() {
super.onStart()
val width = (resources.displayMetrics.widthPixels * 0.95).toInt()
val height = (resources.displayMetrics.heightPixels * 0.43).toInt()
dialog!!.window?.setLayout(width, height)
dialog!!.setCanceledOnTouchOutside(true)
}
Related
i'm a beginner. I need help. I don't understand how access the value of seekbar in my adapter.
I want to retrieve the values of the seekbars to transfer them to the adapter level in order to update the user evaluation.
I have a fragment EvalGroupFragment and the adapter EvalGroupAdapter.
I don't know how i can to access the values of the seekbars. Thanks you so much for your help.
Here is my code of my EvalGroupFragment:
class EvalGroupFragment: Fragment() {
private var custom_progress_relation: Float = 0.0f
private var custom_progress_trajets : Float = 0.0f
private var noteFinaleTrajets : Float = 0.0f
private var noteFinaleRelation : Float = 0.0f
private var _binding: FragmentEvalGroupBinding? = null
private val binding get() = _binding!!
private lateinit var mUserEvalViewModel: UserEvalViewModel
private val args by navArgs<EvalGroupFragmentArgs>()
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
_binding = FragmentEvalGroupBinding.inflate(inflater, container, false)
val view = binding.root
//Recyclerview pour afficher le custom row et les données
val adapter = EvalGroupAdapter()
val recyclerView = view.findViewById<RecyclerView>(R.id.recyclerviewEvalGroup)
recyclerView?.adapter = adapter
recyclerView?.layoutManager = LinearLayoutManager(requireContext())
// UserViewModel pour afficher les données
mUserEvalViewModel = ViewModelProvider(this).get(UserEvalViewModel::class.java)
val nbTeam = args.currentUserWithEval.nbTeam
val _nbTeam = nbTeam.toString()
val gru_id = args.currentUserWithEval.gru_id_reference
mUserEvalViewModel.getGruUser(gru_id, _nbTeam).observe(
viewLifecycleOwner,
) { user ->
user.let {
adapter.setDataGroup(user)
}
}
binding.seekbarRelationGroup.setOnSeekBarChangeListener(object:
SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(
seekBar: SeekBar?,
progress: Int,
fromUser: Boolean)
{
var aFloat = progress * 0.1
custom_progress_relation = (floor(10 * aFloat + 0.5) / 10).toFloat()
noteFinaleRelation = custom_progress_relation.toFloat()
binding.noteAFL1RelationGroup.setText(custom_progress_relation.toString() + " " + " /4")
}
override fun onStartTrackingTouch(seekBar: SeekBar?) {
}
override fun onStopTrackingTouch(seekBar: SeekBar?) {
}
})
binding.seekbarTrajetsGroup.setOnSeekBarChangeListener(object:
SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(
seekBar: SeekBar?,
progress: Int,
fromUser: Boolean)
{
var aFloat = progress * 0.1
custom_progress_trajets = (floor(10 * aFloat + 0.5) / 10).toFloat()
noteFinaleTrajets = custom_progress_trajets.toFloat()
binding.noteAFL1TrajetsGroupGroup.setText(custom_progress_trajets.toString() + " " + " /4")
}
override fun onStartTrackingTouch(seekBar: SeekBar?) {
}
override fun onStopTrackingTouch(seekBar: SeekBar?) {
}
})
// Add menu
setHasOptionsMenu(true)
return view
}
private fun saveEvalInDatabase() {
val idEval = 0
note_seize = args.currentUserWithEval.note_seize
note_douze = args.currentUserWithEval.note_douze
note_relation = noteFinaleRelation.toString().trim()
note_trajets = noteFinaleTrajets.toString().trim()
note_moteur = args.currentUserWithEval.note_moteur
note_emotion = args.currentUserWithEval.note_emotion
note_afl2 = args.currentUserWithEval.note_afl2
note_afl3 = args.currentUserWithEval.note_afl3
note_sur_vingt = args.currentUserWithEval.note_sur_vingt
user_id_reference = args.currentUserWithEval.user_id_reference
val eval = Eval(idEval, note_seize, note_douze, note_relation, note_trajets, note_moteur, note_emotion, note_afl2, note_afl3, note_sur_vingt, user_id_reference)
Toast.makeText(context, eval.toString(), Toast.LENGTH_LONG).show()
mEvalViewModel.updateEval(eval)
}
private fun clicSound() {
val mediaPlayer: MediaPlayer = MediaPlayer.create(context, R.raw.select_click)
mediaPlayer.start()
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.delete_menu, menu)
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
and here is my code of my adapter: EvalGroupAdapter
class EvalGroupAdapter: RecyclerView.Adapter<EvalGroupAdapter.MyViewHolder>() {
var userList = emptyList<UserWithEval>()
class MyViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.custom_group_details, parent, false))
}
override fun getItemCount(): Int {
return userList.size
}
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
val currentItemEvalGroup = userList[position]
holder.itemView.findViewById<TextView>(R.id.lastName_txt_details).text = currentItemEvalGroup.lastName.uppercase()
holder.itemView.findViewById<TextView>(R.id.firstName_txt_details).text = currentItemEvalGroup.firstName.uppercase()
holder.itemView.findViewById<TextView>(R.id.numeroTeam_txt_details).text = currentItemEvalGroup.nbTeam.uppercase()
}
fun setDataGroup(user: List<UserWithEval>){
this.userList = user
notifyDataSetChanged()
}
}
and here is my recyclerview:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="2sp"
android:layout_marginTop="30dp"
android:background="#drawable/row_add_user"
android:id="#+id/rowLayoutDetails">
<TextView
android:id="#+id/lastName_txt_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nom"
android:layout_marginLeft="120dp"
android:textSize="25sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/firstName_txt_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="100dp"
android:layout_marginLeft="100dp"
android:text="Prénom"
android:textSize="25sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="#+id/lastName_txt_details"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/numeroTeam_txt_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="100dp"
android:layout_marginLeft="100dp"
android:text="(2)"
android:textSize="25sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="#+id/firstName_txt_details"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/btn_confirmation_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:background="#drawable/rectangle_titre"
android:text="SAVE"
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="#+id/lastName_txt_details"
app:layout_constraintStart_toEndOf="#+id/numeroTeam_txt_details"
app:layout_constraintTop_toTopOf="#+id/lastName_txt_details" />
</androidx.constraintlayout.widget.ConstraintLayout>
and my fragment_eval_group xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/linear_gradient_bg"
android:orientation="horizontal"
android:id="#+id/fragEvalGroup">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerviewEvalGroup"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
<LinearLayout
android:id="#+id/linear_afl1_relation_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="250dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/view_v_1">
<TextView
<LinearLayout
android:id="#+id/linear_seekbar_relation_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tableau_relation_group">
<SeekBar
android:id="#+id/seekbar_relation_group"
android:layout_width="700dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:max="40"
android:min="0"
android:progress="0"
android:progressDrawable="#drawable/custom_seekbar"
android:thumb="#drawable/custom_thumb" />
</LinearLayout>
<com.google.android.material.divider.MaterialDivider
android:id="#+id/divider_relation_trajets_group"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="10dp"
app:dividerColor="#color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linear_seekbar_relation_group" />
//FIN LINEAR AFL1 RELATION
//LINEAR AFL1 TRAJETS
<LinearLayout
android:id="#+id/linear_afl1_trajets_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/divider_relation_trajets_group">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:background="#drawable/rectangle_titre"
android:padding="10dp"
android:text="Trajets"
android:textColor="#23203D"
android:textSize="22sp"
android:textStyle="bold" />
<Space
android:layout_width="300dp"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/noteAFL1_TrajetsGroup_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/custom_input_eval"
android:gravity="center_horizontal"
android:padding="5dp"
android:text=" /4"
android:textAlignment="center"
android:textColor="#23203D"
android:textSize="#dimen/size_note" />
</LinearLayout>
<LinearLayout
android:id="#+id/tableau_trajets_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linear_afl1_trajets_group">
<TableLayout
android:id="#+id/table_Trajets_group"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:stretchColumns="0,2, 4 , 6">
<TableRow
android:id="#+id/firstRowTrajets"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!-- first element of the row-->
<TextView
android:id="#+id/simpleTextView1Trajets"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#99FADF16"
android:gravity="right"
android:padding="18dip"
android:text="0 0.5"
android:textColor="#000"
android:textSize="22sp"
android:textStyle="bold" />
<TextView
android:id="#+id/simpleTextView3Trajets"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#99A99EFF"
android:gravity="center"
android:padding="18dip"
android:text="0.5 1 2"
android:textColor="#000"
android:textSize="22sp"
android:textStyle="bold" />
<TextView
android:id="#+id/simpleTextView5Trajets"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#99FA6148"
android:gravity="center"
android:padding="18dip"
android:text="2 2.5 3"
android:textColor="#000"
android:textSize="22sp"
android:textStyle="bold" />
<TextView
android:id="#+id/simpleTextView7Trajets"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#99FCEC83"
android:gravity="left"
android:padding="18dip"
android:text="3 4"
android:textColor="#000"
android:textSize="22sp"
android:textStyle="bold" />
</TableRow>
<com.google.android.material.divider.MaterialDivider
android:layout_width="match_parent"
android:layout_height="1dp"
app:dividerColor="#color/black" />
<TableRow
android:id="#+id/secondRowTrajets_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_span="1"
android:background="#99FADF16"
android:gravity="center"
android:text=" - Choré. statique \n - Trajets en Aller-Retour \n - Pas de sol "
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_span="1"
android:background="#99BAFA16"
android:gravity="center"
android:text=" - Faible utilisation de \n l'espace scénique \n - Passage au sol \n et redressement maladroit"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_span="1"
android:background="#99FA6148"
android:gravity="center"
android:text=" - Bonne utilisation de \n l'espace scénique \n - Utilisation du sol"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_span="1"
android:background="#99FCEC83"
android:gravity="center"
android:text=" - Très bonne utilisation \n de l'espace scénique\n - Trajets riches et variés \n - Le sol sert le propos"
android:textSize="18sp"
android:textStyle="bold" />
</TableRow>
</TableLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_seekbar_trajets_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tableau_trajets_group">
<SeekBar
android:id="#+id/seekbar_trajets_group"
android:layout_width="700dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:max="40"
android:min="0"
android:progress="0"
android:progressDrawable="#drawable/custom_seekbar"
android:thumb="#drawable/custom_thumb" />
</LinearLayout>
<LinearLayout
android:layout_width="300dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linear_seekbar_trajets_group">
<Button
android:id="#+id/btn_confirmation_eval_group"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="SAVE"
android:textSize="30sp"
android:textStyle="bold"
android:background="#drawable/rectangle_1"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Data Set custom listview in Dialog Fragment using BaseAdapter. when select list item then only text item selected, whole row is not selected.
CustomDialog.kt
class CustomDialog(val servList: ArrayList<Serve>) : DialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val inflater = context?.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val binding = DialogListViewBinding.inflate(inflater)
val builder = AlertDialog.Builder(requireContext())
val servAdapter = DialogListAdapter(servList, requireContext())
binding.listViewDialog.adapter = servAdapter
servAdapter.notifyDataSetChanged()
val dialog = builder.create()
dialog.show()
binding.listViewDialog.isClickable = true
binding.listViewDialog.setOnItemClickListener { adapterView, view, i, l ->
val serve = adapterView.getItemAtPosition(i) as Serve
val serve1 = serve.serveNo
dialog.dismiss()
/* (activity as AddProduct?)..setText(input)*/
mOnInputListener?.sendInput(serve1.toString())
Toast.makeText(requireContext(), serve1.toString(), Toast.LENGTH_LONG).show()
}
return binding.root
}
DialogListAdapter.kt
class DialogListAdapter (val servNo : ArrayList<Serve>,val context: Context) : BaseAdapter() {
override fun getCount(): Int {
return servNo.size
}
override fun getItem(p0: Int): Serve = servNo[p0]
override fun getItemId(p0: Int): Long {
return p0.toLong()
}
override fun getView(p0: Int, p1: View?, p2: ViewGroup?): View {
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val binding = DialogListItemBinding.inflate(inflater)
val ser = servNo.get(p0)
binding.tvListViewDialogItem.text = ser.serveNo
return binding.root
}
}
dialog_list_view.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout"
android:layout_width="0dp"
android:layout_height="60dp"
android:background="#FFD700"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<!-- android:background="#FFD700"-->
<!--android:background="#color/dark_green"-->
<ImageView
android:id="#+id/imgDialogListClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="9dp"
android:src="#drawable/ic_clear_black_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/tvDialogListTitle"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/tvDialogListTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:text="Select Serve No"
android:textSize="22sp"
android:textStyle="bold"
android:textColor="#color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/imgDialogListClear"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<ListView
android:id="#+id/listViewDialog"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/constraintLayout"/>
</androidx.constraintlayout.widget.ConstraintLayout>
dialog_list_item.xml
[![<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="#+id/tvListViewDialogItem"
android:gravity="center"
android:padding="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Above Image Listview item selected second item only text item part selected in yellow border. Green border part is not selected, so list item whole row is not selected. how to its selected?
I want to know when I am at the bottom of my recycler view but I can't get why the recyclerView.canScrollVertically(1) is always returning true even if I am at the bottom of the Recycler View.
The recycler view is inside a CoordinatorLayout with an AppBarLayout.
You have the Kotlin code and the XML code for the bigger picture
Thank you.
getDataBinding().shipmentRecyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
Log.e(TAG,
"onScrollStateChanged 1: This is the bottom shipmentRecyclerView $newState <> ${RecyclerView.SCROLL_STATE_IDLE} ${
recyclerView.canScrollVertically(1)
}")
if (!getDataBinding().shipmentRecyclerView.canScrollVertically(1) && newState == RecyclerView.SCROLL_STATE_IDLE) {
Log.e(TAG, "onScrollStateChanged 2: This is the bottom shipmentRecyclerView")
if (viewModel.currentPage.get()!! < viewModel.totalPages.get()!!) {
viewModel.getShipmentByPage(
viewModel.currentPage.get()!! + 1,
viewModel.request.get()
)
}
}
}
})
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<import type="android.view.View" />
<variable
name="viewModel"
type="com.technifyit.jibheli.presentation.main.fragment.search.SearchViewModel" />
</data>
<com.sothree.slidinguppanel.SlidingUpPanelLayout
android:id="#+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
app:umanoPanelHeight="0dp"
app:umanoShadowHeight="#dimen/margin_4dp"
tools:context=".presentation.main.fragment.search.SearchFragment">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/shipment_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="#dimen/margin_12dp"
android:clipToPadding="true"
android:fastScrollEnabled="true"
app:layout_anchor="#id/app_bar_layout"
app:layout_anchorGravity="bottom"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
app:shipment_adapter="#{viewModel}" />
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/dark_color_purple"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
...........
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/dark_color_purple"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:visibility="gone"
app:contentInsetStart="0dp"
app:layout_anchor="#id/app_bar_layout"
app:layout_anchorGravity="bottom"
app:layout_collapseMode="pin"
app:theme="#style/ThemeOverlay.AppCompat.Dark"
app:title="">
.........
</androidx.appcompat.widget.Toolbar>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/custom_web_page_browser"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/margin_40dp"
android:background="#drawable/background_rounded_top"
android:backgroundTint="#color/grey_clair">
<com.technifyit.jibheli.presentation.customView.MontserratBoldTextView
android:id="#+id/url_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/margin_20dp"
android:layout_marginEnd="#dimen/margin_6dp"
android:text="#string/activity_item_details_send_request_button_text"
android:textColor="#color/dark_color_purple"
android:textSize="#dimen/title_size_sign_up"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="#id/close"
app:layout_constraintEnd_toStartOf="#id/use_link_image_view"
app:layout_constraintStart_toEndOf="#id/close"
app:layout_constraintTop_toTopOf="#id/close" />
<ImageView
android:id="#+id/close"
android:layout_width="#dimen/icon_24dp"
android:layout_height="#dimen/icon_24dp"
android:layout_margin="#dimen/margin_6dp"
android:background="#drawable/ic_close_gold"
android:backgroundTint="#color/dark_color_purple"
android:padding="#dimen/margin_4dp"
android:src="#drawable/ic_close_native"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tint="#color/white" />
<com.technifyit.jibheli.presentation.customView.MontserratBoldTextView
android:id="#+id/use_link_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_6dp"
android:background="#drawable/button_rounded_left_only_no_icon"
android:backgroundTint="#color/dark_color_purple"
android:drawableEnd="#drawable/ic_check_native"
android:drawablePadding="#dimen/margin_6dp"
android:gravity="center"
android:paddingStart="#dimen/margin_8dp"
android:paddingEnd="#dimen/margin_8dp"
android:text="#string/select"
android:textAllCaps="false"
android:textColor="#color/white"
app:drawableTint="#color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="#dimen/margin_4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#id/close">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include
android:id="#+id/no_item_found_suggested_layout"
layout="#layout/no_item_found_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/requested_shipments_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_6dp"
android:fastScrollEnabled="true"
app:layout_constraintTop_toTopOf="parent"
app:requested_shipment_adapter="#{viewModel}" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/requested_trip_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_6dp"
android:fastScrollEnabled="true"
app:layout_constraintTop_toTopOf="parent"
app:requested_trip_adapter="#{viewModel}" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
</layout>
Thank you for your response, i did find a solution by adding to my recycler view in xml
addOnScrolledToBottomListener="#{viewModel}" and then in the bindingAdapter
#BindingAdapter("addOnScrolledToBottomListener")
fun addOnScrolledToBottomListener(recyclerView: RecyclerView, viewModel: SearchViewModel) {
recyclerView.addOnScrollListener(object :
RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
if (recyclerView.canScrollVertically(1) && newState == RecyclerView.SCROLL_STATE_IDLE) {
if (viewModel.currentPage.get()!! < viewModel.totalPages.get()!!) {
viewModel.getShipmentByPage(
viewModel.currentPage.get()!! + 1,
viewModel.request.get()
)
}
}
}
})
}`
and like that it worked like a charm, Thank you #xinaiz for your help
I try to do a button for switch from a main activity to an other, but when I try to run the app, it close itself immediatly after click on the app. I find in the command that message of error :
Unable to start activity ComponentInfo{fr.amseu.mystretching/fr.amseu.mystretching.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageButton.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
My code in the MainActivity is this one :
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val button = findViewById<ImageButton>(R.id.imageButton)
button.setOnClickListener {
val intent = Intent(this, SecondActivity::class.java)
startActivity(intent);}
That is my Main Activity :
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/item_main"
android:background="#color/light_red">
<androidx.cardview.widget.CardView
android:id="#+id/cardView"
android:layout_width="100dp"
android:layout_height="120dp"
app:cardCornerRadius="8dp"
app:cardElevation="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageButton
android:id="#+id/imageButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/lower_legs"
android:contentDescription="#string/home_page_first_button" />
</androidx.cardview.widget.CardView>
<View
android:id="#+id/view_separation"
android:layout_width="match_parent"
android:visibility="invisible"
android:layout_height="1dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="#+id/name_item"
style="#style/SubTitleTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/default_margin"
android:text="#string/home_page_first_button"
app:layout_constraintBottom_toTopOf="#+id/view_separation"
app:layout_constraintStart_toEndOf="#+id/cardView"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/description_item"
style="#style/DefaultTextStyle"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="#string/home_page_description_1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="#+id/name_item"
app:layout_constraintTop_toBottomOf="#+id/view_separation" />
</androidx.constraintlayout.widget.ConstraintLayout>
And for my recycler view, I take this model in my page and the following item are siblings but I change the image and texts, with an adapter, HomeFragment...
Can someone help me please ?
(It is my first app)
Thanks a lot !
I have this id in XML <EditText android:id="#+id/search_edit_text" , how to import to the kotlin file. In kotlin file need use this view.search_edit_text.addTextChangedListener for my program , but appear this error "Unresolved reference: search_edit_text"
a little of my program source :
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
val view = inflater.inflate(R.layout.fragment_search, container, false)
recyclerView = view.findViewById(R.id.recycler_view_search)
recyclerView?.setHasFixedSize(true)
recyclerView?.layoutManager = LinearLayoutManager(context)
mUser = ArrayList()
userAdapter = context?.let { UserAdapter(it, mUser as ArrayList<User>, true) }
recyclerView?.adapter = userAdapter
view.search_edit_text.addTextChangedListener(object: TextWatcher
my XML file:
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/app_bar_layout_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<androidx.appcompat.widget.Toolbar
android:id="#+id/search_toolbar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#android:color/white">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/search_fragment_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/search" />
<EditText
android:id="#+id/search_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:layout_toEndOf="#+id/search_fragment_icon"
android:hint="Pesquisar..."
android:textColor="#color/colorPrimary" />
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view_search"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/app_bar_layout_search"
android:visibility="gone"></androidx.recyclerview.widget.RecyclerView>
</RelativeLayout>