다음 예에서 나는 onCreateDialog
및 showDialog
가 지원 중단되었습니다.API 17에서 Android에서 AlertDialog를 계속 사용할 수 있습니까?
package com.dialogtest;
import android.app.Dialog;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
CharSequence[] items = {"Google", "Apple", "Microsoft"};
// Declare the boolean array of same size as items
boolean[] itemsChecked = new boolean[items.length];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick(View v) {
showDialog(1);
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case 1:
return new AlertDialog.Builder(this)
//.setIcon(R.drawable.ic_launcher)
.setTitle("This is a dialog with some simple text...")
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Toast.makeText(getBaseContext(),
"OK clicked!", Toast.LENGTH_SHORT).show();
}
}
)
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Toast.makeText(getBaseContext(),
"Cancel clicked!", Toast.LENGTH_SHORT).show();
}
}
)
.setMultiChoiceItems(items, itemsChecked,
new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog,
int which, boolean isChecked) {
Toast.makeText(getBaseContext(),
items[which] + (isChecked ? " checked!" : " unchecked!"),
Toast.LENGTH_SHORT).show();
}
}
).create();
}
return null;
}
}
나는 DialogFragment를 사용하도록 제안되었지만 확실하지 않습니다.
AlertDialog를 더 이상 사용할 수 없다는 것을 알고 싶습니다.
[http://stackoverflow.com/questions/10285047/showdialog-deprecated-whats-the-alternative](http://stackoverflow.com/ 질문/10285047/showdialog-deprecated-whats-the-alternative) –
은 사용자가 사용할 수 없다는 의미가 아닙니다. 그들은 향후 버전에서 제거 될 것이므로 이러한 메소드를 사용하지 않아야한다고 경고하고 있습니다. –
Appcompat AlertDialog를 사용해보십시오. appcompat 버전으로 전환하는 것이 많은 영향을 줄 것이라고 생각하지 않습니다. – shadygoneinsane