Estoy haciendo el más simple de los modelos onClick y no puedo hacer que el método onClick se dispare. Sé que es algo simple, y soy nuevo en Android. Cualquier ayuda es apreciada.método onClick no llamado en Android
package com.bordeloniphone.timeentry;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class TimeEntryActivity extends Activity implements OnClickListener{
/** Called when the activity is first created. */
Button okButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
okButton = (Button) findViewById(R.id.btnOK);
okButton.setText(":)");
okButton.setOnClickListener(this);
//setContentView(okButton);
}
public void onClick(View v) {
Log.d("TEST", "TEST");
Toast.makeText(this, "TEST", Toast.LENGTH_SHORT).show();
}
}
Aquí es el main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/btnOK"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:text="OK" />
</LinearLayout>
Copié/pegué su código exacto en un nuevo proyecto y funcionó. Obtengo la entrada de brindis y LogCat. ¿Qué te hace pensar que no está funcionando? – kabuko
Tu código funciona bien para mí ... Comprueba después de limpiar y crea tu proyecto ... – deepa
Sí, este código funciona para mí. Tal vez puedas probar: Toast.makeText (TimeEntryActivity.this, "TEST", Toast.LENGTH_SHORT) .show(); – R4j