3 回答
TA贡献1865条经验 获得超7个赞
如果您希望其他类能够调用它,请将其showAlertDialog protected改为,甚至公开。private
protected void showAlertDialog(final Context context) {
}
私有方法不能被覆盖。
TA贡献1887条经验 获得超5个赞
如果你想覆盖一个方法使用 抽象 关键字
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();
}
添加回答
举报