2017-06-23 70 views
-1

activity_verify.xml按鈕沒有響應應用的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(); 
. 
. 
. 
} 
     }); 
    } 
. 
. 
. 

的logcat的消息,所有的解決方案後,單擊 「按鈕點擊/ yaah!」永遠不會顯示,onClick方法中的toast消息從不顯示。該按鈕根本不點擊。 我已經經歷了所有的代碼和計算器的問題了,我不知道什麼是錯我的代碼,而在我創建較早的其他應用程序,同樣的代碼是完美的工作。

+0

做這個日誌打印或不Log.d(「按鈕」,「輸入到buttonVerify」); @ sonubig909 –

+0

@NileshRathod是除了按鈕的onclick方法裏面的日誌消息每個日誌消息 – robstat7

+0

只是儘量一次把點擊監聽器的代碼onCreate()方法 –

回答

1

你能this.requestWindowFeature(Window.FEATURE_NO_TITLE);上述排隊setContentView(R.layout.test);

參見:http://prntscr.com/fn7zhe

您的活動

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(); 

      } 
     }); 
    } 
} 

參見:佈局文件

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

請檢查我的更新答案。 –

+0

不工作:(按鈕根本沒有點擊,也沒有任何東西 – robstat7

+0

什麼問題我使用相同的代碼,你給我的問題,我只是改變上面的mentation,它的工作看到的截圖 –

0

刪除buttonVerify()方法... U se 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

應用程序崩潰! – robstat7

+0

在按鈕單擊事件中使用getdata()函數.... –