第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何從擴(kuò)展活動(dòng)覆蓋方法?

如何從擴(kuò)展活動(dòng)覆蓋方法?

夢(mèng)里花落0921 2022-07-14 17:29:03
我有 2 個(gè)活動(dòng)。一是AlertDialogActivity& 二是MainActivity。我AlertDialogActivity在MainActivity.像這樣public class MainActivity extends AlertDialogActivity現(xiàn)在如何覆蓋AlertDialogActivity我的方法MainActivity?警報(bào)對(duì)話(huà)活動(dòng):package com.jimmytrivedi.alertdialog;import android.app.AlertDialog;import android.app.Dialog;import android.content.Context;import android.os.Bundle;import android.widget.EditText;import android.widget.TextView;import androidx.appcompat.app.AppCompatActivity;public class AlertDialogActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_alert_dialog);        showAlertDialog(AlertDialogActivity.this);    }    private void showAlertDialog(final Context context) {        // 1. Instantiate an <code><a href="/reference/android/app/AlertDialog.Builder.html">AlertDialog.Builder</a></code> with its constructor        AlertDialog.Builder builder = new AlertDialog.Builder(AlertDialogActivity.this);// 2. Chain together various setter methods to set the dialog characteristics        builder.setMessage("How are you?")                .setTitle("Hello");// 3. Get the <code><a href="/reference/android/app/AlertDialog.html">AlertDialog</a></code> from <code><a href="/reference/android/app/AlertDialog.Builder.html#create()">create()</a></code>        AlertDialog dialog = builder.create();        dialog.show();    }}
查看完整描述

3 回答

?
莫回?zé)o

TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊

如果您希望其他類(lèi)能夠調(diào)用它,請(qǐng)將其showAlertDialog protected改為,甚至公開(kāi)。private


protected void showAlertDialog(final Context context) {


}

私有方法不能被覆蓋。


查看完整回答
反對(duì) 回復(fù) 2022-07-14
?
慕工程0101907

TA貢獻(xiàn)1887條經(jīng)驗(yàn) 獲得超5個(gè)贊

如果你想覆蓋一個(gè)方法使用 抽象 關(guān)鍵字


public abstract class AlertDialogActivity extends AppCompatActivity {



@Override

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_alert_dialog);

    showAlertDialog(AlertDialogActivity.this);

}


  public abstract void showAlertDialog(final Context context) {


    // 1. Instantiate an <code><a href="/reference/android/app/AlertDialog.Builder.html">AlertDialog.Builder</a></code> with its constructor

    AlertDialog.Builder builder = new AlertDialog.Builder(AlertDialogActivity.this);


  // 2. Chain together various setter methods to set the dialog characteristics

    builder.setMessage("How are you?")

            .setTitle("Hello");


   // 3. Get the <code><a 

  href="/reference/android/app/AlertDialog.html">AlertDialog</a></code> from <code><a 

  href="/reference/android/app/AlertDialog.Builder.html#create()">create()</a></code>

    AlertDialog dialog = builder.create();

    dialog.show();



}


查看完整回答
反對(duì) 回復(fù) 2022-07-14
?
largeQ

TA貢獻(xiàn)2039條經(jīng)驗(yàn) 獲得超8個(gè)贊

方法應(yīng)該具有相同的名稱(chēng)和類(lèi)型。方法也不應(yīng)該是私有的。



查看完整回答
反對(duì) 回復(fù) 2022-07-14
  • 3 回答
  • 0 關(guān)注
  • 183 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)