Ich habe eine Vorlagenansicht, wie es aussieht;Aufgeblähte Ansicht fängt onClick-Ereignis nicht an
template.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/contentLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/view_background"
android:gravity="center_vertical"
tools:context=".MainActivity" >
<Button
android:id="@+id/btnMultiple"
android:layout_width="0dp"
android:layout_height="150dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:background="@drawable/button_backgroundblue"
android:onClick="btnMultiple_clicked"
android:tag="4"
android:text="@string/mc_abcd"
android:textColor="@drawable/button_textcolor"
android:textSize="@dimen/h2" />
ich diese Ansicht programmatisch erstellen und dann bin ich das Hinzufügen dieser Ansicht in ViewFlipper wie dergleichen;
activity_main.java
public void btnCreateView_clicked(View view) {
ViewFlipper viewFlipper = (ViewFlipper)findViewById(R.id.flipper);
View myView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.template, viewFlipper, false);
viewFlipper.addView(myView);
viewFlipper.showNext(); // Showing lastly created myView successfully. }
Auch meine Tätigkeit öffentliche Funktion als wie hat;
activity_main.java
public void btnMultiple_clicked(View view) {
//Save the world !
}
Wenn i btnCreateView Taste von der ersten Ansicht Presse erfolgreich Erstellen Vorlage (myView) und dann in ViewFlipper Zugabe. Wenn ich auf btnMultiple klicke, bekomme ich einen Fehler und meine Anwendung stürzt ab; "In der Aktivitätsklasse android.app.Application für den onClick-Handler der View-Klasse android.widget.Button mit der ID 'btnMultiple' konnte ich keine Methode btnMultiple_clicked (View) finden." Ich bin mir sicher, dass es eine existierende Methode btnMultiple_clicked (View) gibt.
PS! Wenn ich Listener zu BtnMultiple programmatisch hinzufügen, wird es funktionieren, aber ich frage mich, warum "android: onClick =" btnMultiple_clicked "" nicht funktioniert?
Oh, hab es, danke für deine Hilfe. Es wirkt wie ein Zauber. –