找不到方法的onClick [英] Can't find onClick method

查看:749
本文介绍了找不到方法的onClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我得到这个错误

11-15 16:55:40.617: E/AndroidRuntime(316): java.lang.IllegalStateException: Could not find a method ingresarBtnClick(View) in the activity class android.view.ContextThemeWrapper for onClick handler on view class android.widget.Button with id 'ingresarButton'

这是我的布局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" android:weightSum="1" android:id="@+id/Login">
    <TextView android:layout_width="wrap_content" android:id="@+id/textView1" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Número de Lecturista" android:layout_height="wrap_content"></TextView>
    <EditText android:inputType="number" android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/numLecEditText" android:maxLength="4">
        <requestFocus></requestFocus>       
    </EditText>
    <TextView android:layout_width="wrap_content" android:id="@+id/textView2" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_height="wrap_content" android:text="PIN"></TextView>
    <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="number" android:password="true" android:id="@+id/pinEditText" android:maxLength="4"></EditText>
    <TableRow android:id="@+id/tableRow1" android:layout_width="match_parent" android:layout_height="wrap_content">
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ingresar" android:id="@+id/ingresarButton" android:onClick="ingresarBtnClick"></Button>
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Salir" android:id="@+id/salirButton" android:onClick="salirBtnClick"></Button>
        <Button android:id="@+id/opcionesButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Opciones" android:onClick="opcionesBtnClick" ></Button>
    </TableRow>
</LinearLayout>

这是我的code

And this is my code

import android.app.Dialog;
import android.view.View;
import android.widget.EditText;

public class FormaLogin extends Dialog
{
    SisLec sisLec;

    public FormaLogin(SisLec _sisLec)
    {       
        super(_sisLec);     
        sisLec = _sisLec;       
        setTitle("Identificación de Lecturista");
    }

    public void mostrar()
    {
        setContentView(R.layout.login);
        show();
    }

    public void ingresarBtnClick(View view)
    {
        EditText numLecTxt = (EditText) sisLec.findViewById(R.id.numLecEditText);
        EditText pinTxt = (EditText) sisLec.findViewById(R.id.pinEditText);

        if(numLecTxt.getText().length() > 0)
        {
            if(pinTxt.getText().length() > 0)
            {
                if(numLecTxt.getText().equals("1337"))
                {
                    if(pinTxt.getText().equals("8383"))
                    {
                        //sisLec.frmMantenimiento.mostrar();
                    }
                }
                else
                {
                    HiloIdentificacion hiloIden = new HiloIdentificacion();
                    hiloIden.identificacion(numLecTxt.getText().toString(), pinTxt.getText().toString());
                }
            }
            else
                sisLec.mensaje("Debe de ingresar su pin");
        }
        else
            sisLec.mensaje("Debe de ingresar su número de Lecturista");
    }

    public void salirBtnClick(View view)
    {
        sisLec.salir();
    }

    public void opcionesBtnClick(View view)
    {
        // TODO: Agregar método que muestre la forma de Opciones
    }

    private class HiloIdentificacion extends Thread
    {
        private String usuario, pass;

        public synchronized void run()
        {
            try
            {
                sisLec.identificacion(usuario, pass);
            }
            catch(Exception e)
            {
                // TODO: Agregar registro de error
            }                   
        }

        public synchronized void identificacion(String _usuario, String _pass)
        {
            usuario = _usuario;
            pass = _pass;
            run();
        }
    }
}

分配给键ingresarButton的方法,ingresarBtnClick(查看视图)是存在的,因为Androir文档建议 http://developer.android.com/guide/topics/ui/ui-events.html 但窗台,我得到的错误。

The method assigned to the button "ingresarButton", "ingresarBtnClick(View view)" is there, as the Androir documentation suggest http://developer.android.com/guide/topics/ui/ui-events.html but sill I'm getting the error.

请问这有什么关系,我是显示在对话框?

Does it has anything to do that i'm showing this layout on a Dialog?

SisLec是我Activity类

SisLec is my Activity class

推荐答案

安卓的onClick在XML路由事件在活动的方法。但是,你的方法是不是在活动中,其在对话框类。你需要要么有你的活动提出了调用对话框的实例,或者有对话code寄存器本身作为听者的onClick,而不是试图将其设置在布局。

android:onClick in the xml routes the event to the method in the activity. But your method is not in the activity, its in your Dialog class. You'll need to either have your activity forward the call to the instance of the Dialog, or have the dialog code register itself as the onClick listener instead of trying to set it in the layout.

这篇关于找不到方法的onClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆