Wie wir das click-Ereignis übergeben zu container in android?

Ich habe eine Tabelle von FrameLayout wo jeder frame enthält entweder ein ImageView oder eine TextView. Unabhängig von Inhalt im frame will ich die onClick Ereignis erkannt werden, indem die OnClickListener Satz auf den Rahmen.

Wie kann ich das erreichen?

Dies ist mein layout, ich habe insgesamt 5 Zeilen (Hier nur 1).
Wie oben beschrieben habe ich 5 FrameLayouts in jeder Zeile, jeder mit einer TextView. Ich bin nicht in der Lage, meinen OnClickListener auf die TextView, da diese geändert werden können, um eine Bildansicht zur Laufzeit. Deshalb will ich die OnClickListener auf das FrameLayout.

Scheint es, dass der Inhalt des FrameLayout verhindert die Erkennung von click-Ereignis.

    <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>

Hier ist ein Beispiel, wie ich die 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);
            }
        }
Wo ist dein code ?
Post-code für uns zu sehen, was Sie bisher ausprobiert haben.
code wurde Hinzugefügt.

InformationsquelleAutor frmi | 2013-11-28

Schreibe einen Kommentar