IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Kotlin Discussion :

RecyclerView Kotlin Android


Sujet :

Kotlin

  1. #1
    Candidat au Club
    Homme Profil pro
    Etudiants
    Inscrit en
    Avril 2020
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Etudiants
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2020
    Messages : 6
    Points : 3
    Points
    3
    Par défaut RecyclerView Kotlin Android
    Bonjour je suis débutant en Kotlin et je voudrais avoir un peu d'aide,

    Dans mon code actuelle, j'ai seulement créé un listener sur l’ensemble de la ligne c’est à dire le parent.

    Ce que je veux faire c'est de donner la possibilité à l’utilisateur de cliquer sur les enfants (Views) qui composent la ligne du RecyclerView.

    Lorsqu'il clique sur textCours, un message s'affiche du genre " Vous avez cliquer sur le nom" à l’aide d’un Toast.

    Et aussi, lorsqu'il clique sur textTitre, un message s'affiche du genre " Vous avez cliquer sur.." à l’aide d’un Toast.

    Pour connaître sur quels Views l’utilisateur a cliqué.

    Merci

    fa23

  2. #2
    Candidat au Club
    Homme Profil pro
    Etudiants
    Inscrit en
    Avril 2020
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Etudiants
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2020
    Messages : 6
    Points : 3
    Points
    3
    Par défaut Mon code RecyclerView et item_list_note
    Mon code RecyclerView:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    package com.example.ContactActivity
     
    import android.content.Context
    import android.content.Intent
    import android.view.LayoutInflater
    import android.view.View
    import android.view.ViewGroup
    import android.widget.TextView
    import androidx.recyclerview.widget.RecyclerView
    import com.example.notekotlincours1.R
     
    class NoteRecyclerAdapter (private val context: Context, private val notes: List<ContactNote>): RecyclerView.Adapter<NoteRecyclerAdapter.ViewHolder>() {
     
    private val layoutInflater = LayoutInflater.from(context)
     
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
    val itemView = layoutInflater.inflate(R.layout.item_list_note, parent, false)
    return ViewHolder(itemView)
    }
     
    override fun getItemCount() = notes.size
     
    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
    val note = notes[position]
    holder.textCours.text = note.contactInfo?.titreProf
    holder.textTitre.text = note.Commentaire
    holder.notePosition = position
    }
     
    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView){
    val textCours = itemView.findViewById<TextView>(R.id.textCours)
    val textTitre = itemView.findViewById<TextView>(R.id.textTitre)
    var notePosition = 0
     
    init {
    itemView?.setOnClickListener {
    val intent = Intent(context, MainActivity::class.java)
    intent.putExtra(EXTRA_NOTE_POSITION, notePosition)
    context.startActivity(intent)
    }
    }
    }
    }
    Et mon item_list_note:
    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout 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">
     
        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:cardCornerRadius="4dp"
            app:cardElevation="4dp"
            app:cardUseCompatPadding="true"
            app:contentPadding="16dp" >
     
            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/constraintLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
     
                <ImageView
                    android:id="@+id/imageView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="8dp"
                    android:layout_marginTop="8dp"
                    android:layout_marginBottom="8dp"
                    android:tint="@android:color/holo_orange_dark"
                    app:layout_constraintBottom_toBottomOf="@+id/textTitre"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:srcCompat="@drawable/ic_assignment_white_24dp" />
     
                <TextView
                    android:id="@+id/textCours"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="8dp"
                    android:layout_marginTop="8dp"
                    android:layout_marginEnd="8dp"
                    android:text="TextView"
                    android:textAppearance="@style/TextAppearance.AppCompat.Body2"
                    android:textColor="@android:color/holo_orange_dark"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toEndOf="@+id/imageView"
                    app:layout_constraintTop_toTopOf="parent" />
     
                <TextView
                    android:id="@+id/textTitre"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    android:layout_marginEnd="8dp"
                    android:layout_marginBottom="8dp"
                    android:text="TextView"
                    android:textAppearance="@style/TextAppearance.AppCompat.Body1"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toStartOf="@+id/textCours"
                    app:layout_constraintTop_toBottomOf="@+id/textCours" />
     
            </androidx.constraintlayout.widget.ConstraintLayout>
     
        </androidx.cardview.widget.CardView>
    </FrameLayout>

  3. #3
    Candidat au Club
    Homme Profil pro
    Conseil - Consultant en systèmes d'information
    Inscrit en
    Mai 2020
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Conseil - Consultant en systèmes d'information

    Informations forums :
    Inscription : Mai 2020
    Messages : 3
    Points : 4
    Points
    4
    Par défaut Réponse
    Bonjour

    Vous avez la possibilité d'identifier la view on utilisant ( findView ById())

    Avec ça vous pouvez identifier la view en question et effectuer le traitement qui va avec.

    Bon courage

Discussions similaires

  1. kotlin android déclaration
    Par sisir8 dans le forum Kotlin
    Réponses: 1
    Dernier message: 09/01/2019, 11h48
  2. Demande aide sur une Notificiation Kotlin (Android)
    Par Stive1987 dans le forum Kotlin
    Réponses: 0
    Dernier message: 02/01/2019, 20h47
  3. Réponses: 9
    Dernier message: 20/10/2017, 19h19
  4. [Android] librairie compatibilité Java-Kotlin
    Par sinzen dans le forum Kotlin
    Réponses: 0
    Dernier message: 23/07/2017, 13h27
  5. Réponses: 7
    Dernier message: 01/09/2015, 13h04

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo