2017-06-23 2 views
-1

activity_verify.xmlBouton ne répond pas à cliquer après l'application de toutes les solutions Android

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingLeft="16dp" 
    android:paddingRight="16dp" 
    android:background="#ffffff" 
    android:gravity="center_vertical"> 
<TextView 
     android:id="@+id/countdown" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="20dp" 
     android:focusable="false" 
     android:fontFamily="sans-serif" 
    android:textAppearance="@style/TextAppearance.AppCompat.Display1" 
     android:textColor="@android:color/black" 
     android:textSize="30sp" 
     android:textStyle="bold" /> 
    <EditText 
     android:id="@+id/otp" 
     style="@android:style/Widget.DeviceDefault.Light.EditText" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:inputType="numberDecimal" 
     android:maxLength="4" 
     android:layout_below="@id/countdown" 
     android:layout_marginTop="10dp" 
     android:layout_marginBottom="30dp" 
     android:hint="Enter 4 digit OTP sent to your phone"/> 
    <Button 
     android:id="@+id/verification" 
     style="@style/Widget.AppCompat.Button.Borderless.Colored" 
     android:layout_width="80dp" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_marginBottom="60dp" 
     android:background="@android:color/holo_blue_dark" 
     android:fontFamily="sans-serif" 
     android:text="@string/bttext" 
     android:textAlignment="center" 
     android:textColor="@android:color/white" 
     android:textSize="18sp" 
     android:textStyle="bold" 
     android:layout_below="@id/otp"/> 
    </RelativeLayout> 

Verify.java

package com.example.myapp.appfirst; 

import android.app.Activity; 
import android.content.Context; 
import android.widget.Button; 
import android.view.View.OnClickListener; 
import android.view.View; 
import android.widget.EditText; 
. 
. 
. 

public class Verify extends Activity{ 
    public Button bt; 
    public EditText digits; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_verify); 
     this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
     this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //App with fullscreen 
     this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     bt = (Button) findViewById(R.id.verification); 
     digits = (EditText) findViewById(R.id.otp); 
      getdata(); //This function sends otp to the phone and sets countdown timer for OTP verification 
     Log.d("oncreate","Now going to buttonVerify()"); 
     buttonVerify(); 
    } 

    public void buttonVerify() { 
     Log.d("Button","Entered into buttonVerify"); 
     bt.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Log.d("Button clicked","yaah!!"); 
       Toast.makeText(getBaseContext(),"It's working",Toast.LENGTH_SHORT).show(); 
. 
. 
. 
} 
     }); 
    } 
. 
. 
. 

Le message Logcat "Bouton cliquée/yaah !!" n'a jamais été affiché et le message toast dans la méthode onClick n'est jamais affiché. Le bouton ne clique pas du tout. J'ai parcouru tous les codes et questions sur stackoverflow et je ne sais pas ce qui ne va pas avec mon code alors que dans d'autres applications que j'ai créées plus tôt, le même code fonctionnait parfaitement.

+0

ce journal imprime-t-il ou non Log.d ("Button", "Entered into buttonVerify"); @ sonichig909 –

+0

@NileshRathod oui chaque message de journal sauf le message de journal dans la méthode onclick du bouton – robstat7

+0

juste essayer une fois mettre votre code de l'écouteur de clic dans la méthode oncreate() –

Répondre

1

peut vous this.requestWindowFeature(Window.FEATURE_NO_TITLE); ci-dessus à la ligne setContentView(R.layout.test);

Voir: http://prntscr.com/fn7zhe

votre activité

public class Verify extends Activity { 
    public Button bt; 
    public EditText digits; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(R.layout.activity_verify); 
     this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
     this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //App with fullscreen 

     bt = (Button) findViewById(R.id.verification); 
     digits = (EditText) findViewById(R.id.otp); 
     //getdata(); //This function sends otp to the phone and sets countdown timer for OTP verification 
     Log.d("oncreate", "Now going to buttonVerify()"); 
     buttonVerify(); 
    } 

    public void buttonVerify() { 
     Log.d("Button", "Entered into buttonVerify"); 
     bt.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Log.d("Button clicked", "yaah!!"); 
       Toast.makeText(getBaseContext(), "It's working", Toast.LENGTH_SHORT).show(); 

      } 
     }); 
    } 
} 

Voir: fichier de mise en page

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingLeft="16dp" 
    android:paddingRight="16dp" 
    android:background="#ffffff" 
    android:gravity="center_vertical"> 
    <TextView 
     android:id="@+id/countdown" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="20dp" 
     android:focusable="false" 
     android:fontFamily="sans-serif" 
     android:textAppearance="@style/TextAppearance.AppCompat.Display1" 
     android:textColor="@android:color/black" 
     android:textSize="30sp" 
     android:textStyle="bold" /> 
    <EditText 
     android:id="@+id/otp" 
     style="@android:style/Widget.DeviceDefault.Light.EditText" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:inputType="numberDecimal" 
     android:maxLength="4" 
     android:layout_below="@id/countdown" 
     android:layout_marginTop="10dp" 
     android:layout_marginBottom="30dp" 
     android:hint="Enter 4 digit OTP sent to your phone"/> 
    <Button 
     android:id="@+id/verification" 
     style="@style/Widget.AppCompat.Button.Borderless.Colored" 
     android:layout_width="80dp" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_marginBottom="60dp" 
     android:background="@android:color/holo_blue_dark" 
     android:fontFamily="sans-serif" 
     android:text="bttext" 
     android:textAlignment="center" 
     android:textColor="@android:color/white" 
     android:textSize="18sp" 
     android:textStyle="bold" 
     android:layout_below="@id/otp"/> 
</RelativeLayout> 
+0

s'il vous plaît vérifier ma réponse mise à jour. –

+0

Ne fonctionne pas :(Le bouton ne clique pas du tout et rien Toasts – robstat7

+0

quel est le problème J'utilise le même code que vous avez donné en question.Je fais juste changer comme mentation ci-dessus.et son fonctionnement voit la capture d'écran.Oui –

0

Méthode Remove buttonVerify() ... U se this this ....

public class Verify extends Activity{ 
public Button bt; 
public EditText digits; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_verify); 
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //App with fullscreen 
    this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    bt = (Button) findViewById(R.id.verification); 
    digits = (EditText) findViewById(R.id.otp); 
     getdata(); //This function sends otp to the phone and sets countdown timer for OTP verification 
    Log.d("oncreate","Now going to buttonVerify()"); 
    bt.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Log.d("Button clicked","yaah!!"); 
      Toast.makeText(getBaseContext(),"It's working",Toast.LENGTH_SHORT).show(); 

    } 
       }); 
} 
+0

L'application se bloque! – robstat7

+0

Utilisez la fonction getdata() dans un événement de clic sur un bouton .... –