Comment laissez-cliquez sur l'événement de passer à conteneur dans android?

J'ai une table de FrameLayout où chaque image contient un ImageView ou un TextView. Indépendamment du contenu de l'image, je veux le onClick événement pour être détecté par le OnClickListener fixé sur le cadre.

Comment puis-je y parvenir?

C'est une partie de ma mise en page, j'ai reçu un total de 5 lignes (Ici affichés 1).
Comme décrit ci-dessus, j'ai 5 FrameLayouts dans chaque ligne, chaque contenant un TextView. Je ne suis pas capable de mettre mes OnClickListener sur le TextView étant donné que cela peut être modifié pour une ImageView au moment de l'exécution. C'est pourquoi je veux le OnClickListener sur le FrameLayout.

Il semble que le contenu de la FrameLayout est l'empêchant de détecter l'événement click.

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/gateContainer"
        android:stretchColumns="*">

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center">

            <FrameLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/door1"
                android:clickable="true">

                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:text="New Text"
                    android:id="@+id/textView"
                    android:layout_gravity="center" />

            </FrameLayout>

            <FrameLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/door2" >

                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:text="New Text"
                    android:id="@+id/textView5"
                    android:layout_gravity="center" />
            </FrameLayout>

            <FrameLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/door3" >

                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:text="New Text"
                    android:id="@+id/textView4"
                    android:layout_gravity="center"/>
            </FrameLayout>
     </TableLayout>

Voici un exemple de la façon dont j'ai mis le OnClickListeners:

        View.OnClickListener clickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v){
                //do something
            }
        };

        TableLayout tableLayout = (TableLayout) findViewById(R.id.gateContainer);
        //Go through all TableRows
        for (int i = 0; i < tableLayout.getChildCount(); i++){
            TableRow tableRow = (TableRow) tableLayout.getChildAt(i);
            //Set listener for each FrameView
            for (int j = 0; j < tableRow.getChildCount(); j++){
                FrameLayout frame = (FrameLayout) tableRow.getChildAt(j);

                frame.setOnClickListener(clickListener);
            }
        }
Où est ton code ?
Post un peu de code pour nous de voir ce que vous avez essayé jusqu'à présent.
le code a été ajouté.

OriginalL'auteur frmi | 2013-11-28