2016-09-30 168 views

回答

3

試試這個代碼..只要你有找到你的自定義對話框內的按鈕,使用此代碼.. Button btn_cancel = (Button) dialog.findViewById(R.id.button_cancel);

Custom_dialog.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        final Dialog dialog = new Dialog(Profile.this); 
        dialog.setContentView(R.layout.mainactivity_dialog); 
        dialog.setTitle("This is the Title"); 
        Button btn_cancel = (Button) dialog.findViewById(R.id.button_cancel); 
        btn_cancel.setOnClickListener(new View.OnClickListener() { 
         @Override public void onClick(View v) { 
          dialog.dismiss(); 
         } 
        }); 

        dialog.show(); 

      }); 
+0

Vishnummm93感謝分享你的知識,但這段代碼不工作 – AliShah

+0

@AliShah好吧,然後嘗試一件事刪除buttonclick函數中的所有對話的事情,只是給一個敬酒信息並檢查其工作與否...如果吐司消息的作品,我們可以確認問題是在功能的內部..請嘗試,讓我知道它..我會盡我所能來幫助你..上述代碼工作正常,讓我看看 – vishnumm93

+0

欣賞你的奮鬥,幫助我。由於我是新人,我無法有效地陳述我的問題,vishnu我希望你能夠訪問我的筆記本電腦並自己理解,如果可能的話。 – AliShah

0
Custom_dialog.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Toast.makeText(getContext(), "You Clicked the button", Toast.LENGTH_SHORT).show(); 

     }); 

請檢查該代碼是否是工作或不...它用於檢查您的按鈕點擊是否正常工作。如果你得到吐司消息讓我知道它..

+0

(「報價=新字符串( 」下else塊的報價被顯示「); MTV =(TextView的)findViewById(R.id.textView); 字符串datestr = 」19-03「; SimpleDateFormat的SDF =新的SimpleDateFormat(「dd-MM」); date currentDate = new Date(); if(datestr.equals(sdf.format(currentDate))){ mtv.setText(「today today is March of March」) ; } 否則{ mtv.setText(報價); }') – AliShah

+0

[報價=新字符串( 「下else塊的報價被顯示」); mtv =(TextView)findViewById(R.id.textView); 字符串datestr = 「19-03」; SimpleDateFormat sdf = new SimpleDateFormat(「dd-MM」); 日期currentDate = new Date(); 如果(datestr.equals(sdf.format(的currentdate))){ mtv.setText( 「今天日期是行軍18」); } 否則{ mtv.setText(報價); }] – AliShah

+0

{quote = new String(「The Quote under else block is showing」); mtv =(TextView)findViewById(R.id.textView); String datestr =「19-03」; SimpleDateFormat sdf = new SimpleDateFormat(「dd-MM」); 日期currentDate = new Date(); 如果(datestr.equals(sdf.format(的currentdate))){ mtv.setText( 「今天日期是行軍18」); } 否則{ mtv.setText(報價); }} – AliShah