3 回答
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) {
}
私有方法不能被覆蓋。
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();
}
添加回答
舉報(bào)
