2011-11-15 14 views
6

तो नहीं खोजा जा सका है, मैं यह मेरा लेआउट एक्सएमएलonClick विधि

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

है इस त्रुटि

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' 

हो रही है और ये मेरे कोड

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 (देखें व्यू)" है, क्योंकि एंड्रॉइड प्रलेखन http://developer.android.com/guide/topics/ui/ui-events.html का सुझाव देता है लेकिन मुझे लगता है मुझे त्रुटि मिल रही है।

क्या ऐसा करने के लिए कुछ भी है कि मैं इस लेआउट को संवाद पर दिखा रहा हूं?

SisLec मेरे गतिविधि वर्ग

उत्तर

10

एंड्रॉइड: xml में क्लिक करें गतिविधि को गतिविधि में विधि के लिए रूट करें। लेकिन आपकी पद्धति गतिविधि में नहीं है, यह आपके संवाद वर्ग में है। आपको डायलॉग के उदाहरण पर कॉल को आगे बढ़ाने की आवश्यकता होगी, या डायलॉग कोड को लेआउट में सेट करने की कोशिश करने के बजाय ऑनक्लिक श्रोता के रूप में खुद को पंजीकृत कराना होगा।

+0

पर OnClickLsitener सेट करेंगे और मैं अपने गतिविधि वर्ग साफ करना चाहते थे संभव है, फॉर्म/डायलॉग के वर्ग पर प्रत्येक फॉर्म/डायलॉग बटन ऑनलिक विधि होने पर और ऑनक्लिक लिस्टनर का उपयोग नहीं करना चाहता था, क्लिक विधि को उत्तर देने के लिए धन्यवाद कितना आसान था, जो कोई भी बताता है उसे नहीं मिला यह – CJLopez

+0

वास्तव में यह फ़ंक्शन कॉल को लेआउटइनफ्लैटर से जुड़े बेसकॉन्क्स्ट पर रूट करता है जो इसे बनाता है, किसी भी तरह से यह कहना मुश्किल है कि यह समस्या कितनी मुश्किल है जब यह 4 अलग-अलग ला में लिखा गया है nguages। –

3

onClick विधि गतिविधि कक्षा में रहने की जरूरत है।

+1

धन्यवाद, मुझे नहीं प्रत्येक बटन विधि के साथ गतिविधि वर्ग कुंडलित करना चाहते हैं, लगता है कि मैं प्रत्येक बटन – CJLopez

संबंधित मुद्दे