안드로이드 응용 프로그램, 사용자 정의 목록을 볼 수 있는 디스플레이 작업공간에서 알레르디아로그 싶다.
How can I do this?
아래 목록에 표시하십시오 알레르디아로그 코드를 사용하는 사용자 정의
AlertDialog.Builder builderSingle = new AlertDialog.Builder(DialogActivity.this);
builderSingle.setIcon(R.drawable.ic_launcher);
builderSingle.setTitle("Select One Name:-");
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(DialogActivity.this, android.R.layout.select_dialog_singlechoice);
arrayAdapter.add("Hardik");
arrayAdapter.add("Archit");
arrayAdapter.add("Jignesh");
arrayAdapter.add("Umang");
arrayAdapter.add("Gatti");
builderSingle.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String strName = arrayAdapter.getItem(which);
AlertDialog.Builder builderInner = new AlertDialog.Builder(DialogActivity.this);
builderInner.setMessage(strName);
builderInner.setTitle("Your Selected Item is");
builderInner.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
dialog.dismiss();
}
});
builderInner.show();
}
});
builderSingle.show();
[붽뎄 따르면] [1], 함께 사용할 수 있는 '한' 알레르디아로그 열거합니다 3 종류가 있다.
예를 들어 내가 부여하느뇨 각 같습니다.
기존의 단일 선택 할 수 있는 방법을 제시해 목록 '' 스티엠스 사용할 수 있습니다.
// setup the alert builder
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Choose an animal");
// add a list
String[] animals = {"horse", "cow", "camel", "sheep", "goat"};
builder.setItems(animals, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case 0: // horse
case 1: // cow
case 2: // camel
case 3: // sheep
case 4: // goat
}
}
});
// create and show the alert dialog
AlertDialog dialog = builder.create();
dialog.show();
Ok 버튼을 클릭할 필요 없는 때문에 곧바로 이 리스트를 항목 컨트롤입니다 반환됨 onc리크리스트너 ''.
// setup the alert builder
val builder = AlertDialog.Builder(context)
builder.setTitle("Choose an animal")
// add a list
val animals = arrayOf("horse", "cow", "camel", "sheep", "goat")
builder.setItems(animals) { dialog, which ->
when (which) {
0 -> { /* horse */ }
1 -> { /* cow */ }
2 -> { /* camel */ }
3 -> { /* sheep */ }
4 -> { /* goat */ }
}
}
// create and show the alert dialog
val dialog = builder.create()
dialog.show()
라디오를 통해 수 있는 것을 볼 수 있는 사용자 목록을 버튼를 기존의 목록은 현재 설정은. 이 목록은 세싱글최세이테마스 '' 라디오 단추를 사용하여 만들 수 있는 길이다.
// setup the alert builder
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Choose an animal");
// add a radio button list
String[] animals = {"horse", "cow", "camel", "sheep", "goat"};
int checkedItem = 1; // cow
builder.setSingleChoiceItems(animals, checkedItem, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// user checked an item
}
});
// add OK and Cancel buttons
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// user clicked OK
}
});
builder.setNegativeButton("Cancel", null);
// create and show the alert dialog
AlertDialog dialog = builder.create();
dialog.show();
여기서 내가 선택한 품목으로부터 하드코딩됩니다 확장하지만 추적합니까 it with a 클래스 멤버 변수를 유지할 수 있게 한 진정한 프로젝트.
// setup the alert builder
val builder = AlertDialog.Builder(context)
builder.setTitle("Choose an animal")
// add a radio button list
val animals = arrayOf("horse", "cow", "camel", "sheep", "goat")
val checkedItem = 1 // cow
builder.setSingleChoiceItems(animals, checkedItem) { dialog, which ->
// user checked an item
}
// add OK and Cancel buttons
builder.setPositiveButton("OK") { dialog, which ->
// user clicked OK
}
builder.setNegativeButton("Cancel", null)
// create and show the alert dialog
val dialog = builder.create()
dialog.show()
이 목록은 세트멀티코이스트레마스 확인란 사용할 수 있는 방법이 ''.
// setup the alert builder
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Choose some animals");
// add a checkbox list
String[] animals = {"horse", "cow", "camel", "sheep", "goat"};
boolean[] checkedItems = {true, false, false, true, false};
builder.setMultiChoiceItems(animals, checkedItems, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
// user checked or unchecked a box
}
});
// add OK and Cancel buttons
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// user clicked OK
}
});
builder.setNegativeButton("Cancel", null);
// create and show the alert dialog
AlertDialog dialog = builder.create();
dialog.show();
여기 있는 아이템 목록에 하드코딩됩니다 이미 검사했어요 그들을 추적할 수 있는 가능성이 크다. ',' ArrayList< Integer> 그녀의심장을 있습니다. [문서용으로 예] [1] 에서 자세한 내용을 참조. 'Null' 항목을 설정할 수도 있습니다 점검됩니다 선택하지 않을 경우 언제든 모든 것이 시작.
// setup the alert builder
val builder = AlertDialog.Builder(context)
builder.setTitle("Choose some animals")
// add a checkbox list
val animals = arrayOf("horse", "cow", "camel", "sheep", "goat")
val checkedItems = booleanArrayOf(true, false, false, true, false)
builder.setMultiChoiceItems(animals, checkedItems) { dialog, which, isChecked ->
// user checked or unchecked a box
}
// add OK and Cancel buttons
builder.setPositiveButton("OK") { dialog, which ->
// user clicked OK
}
builder.setNegativeButton("Cancel", null)
// create and show the alert dialog
val dialog = builder.create()
dialog.show()
가져오기의 android.support.v7.app.AppCompatActivity.
public class 마리나스티비티 마카베컴파타스티비티 연장시킵니다 {
컨텍스트로 컨텍스트로.
@Override 금지되었는지 void 언크리치 (Bundle 사브딘스턴스국가) { 스페리언크리치 (사브딘스턴스국가); 세콘텐트비에프 (R. layout.activity_main); 컨텍스트로 = 이. }
public void 쇼와레르디아로그버튼클리히트 (보기 보기) {
이 예제 코드 생성 경고마다 대화상자의 댁이라면 열거합니다 // } }
[1]: https://developer.android.com/guide/topics/ui/dialogs.html # 장딩가리스트
[6]: https://developer.android.com/reference/android/app/AlertDialog.Builder.html # 세섬프터 (안드로이드스위지t.리스트섬프터 20android.content.dialoginterface.onclicklistener, %) [7]: https://developer.android.com/reference/android/app/AlertDialog.Builder.html # 세스쿠르소 (안드로이드리다타바제스커소 20android.content.dialoginterface.onclicklistener 20java.lang.string, %, %) [8]: https://developer.android.com/guide/topics/ui/dialogs.html # 쿠스토무라리우스 [9]: # 40584425 https://stackoverflow.com/questions/40584424/simple-android-recyclerview-example/40584425
사용자 정의 대화 사용할 수 있습니다.
사용자 정의 대화 레이아웃뿐만. '리스트리스메르'
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ListView
android:id="@+id/lv"
android:layout_width="wrap_content"
android:layout_height="fill_parent"/>
</LinearLayout>
자신의 활동
Dialog dialog = new Dialog(Activity.this);
dialog.setContentView(R.layout.list)
ListView lv = (ListView ) dialog.findViewById(R.id.lv);
dialog.setCancelable(true);
dialog.setTitle("ListView");
dialog.show();
편집:
알레르디아로그 사용하여
String names[] ={"A","B","C","D"};
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflater = getLayoutInflater();
View convertView = (View) inflater.inflate(R.layout.custom, null);
alertDialog.setView(convertView);
alertDialog.setTitle("List");
ListView lv = (ListView) convertView.findViewById(R.id.lv);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,names);
lv.setAdapter(adapter);
alertDialog.show();
쿠스토메이휴스믈
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
스냅되지
final CharSequence[] items = {"A", "B", "C"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Make your selection");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
// Do something with the selection
mDoneButton.setText(items[item]);
}
});
AlertDialog alert = builder.create();
alert.show();
',' &Quot 안드로이d.app.일르디아로그 임포트합니다 사용합니다를 "; 그리고 당신이 임포트합니다 쓰기
String[] items = {"...","...."};
AlertDialog.Builder build = new AlertDialog.Builder(context);
build.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//do stuff....
}
}).create().show();
이 너무 간단한
final CharSequence[] items = {"Take Photo", "Choose from Library", "Cancel"};
AlertDialog.Builder builder = new AlertDialog.Builder(MyProfile.this);
builder.setTitle("Add Photo!");
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
if (items[item].equals("Take Photo")) {
getCapturesProfilePicFromCamera();
} else if (items[item].equals("Choose from Library")) {
getProfilePicFromGallery();
} else if (items[item].equals("Cancel")) {
dialog.dismiss();
}
}
});
builder.show();
I would you go as a beginner 제안하세요 통해 http://www.mkyong.com/android/android-custom-dialog-example/
있는 코틀린:
fun showListDialog(context: Context){
// setup alert builder
val builder = AlertDialog.Builder(context)
builder.setTitle("Choose an Item")
// add list items
val listItems = arrayOf("Item 0","Item 1","Item 2")
builder.setItems(listItems) { dialog, which ->
when (which) {
0 ->{
Toast.makeText(context,"You Clicked Item 0",Toast.LENGTH_LONG).show()
dialog.dismiss()
}
1->{
Toast.makeText(context,"You Clicked Item 1",Toast.LENGTH_LONG).show()
dialog.dismiss()
}
2->{
Toast.makeText(context,"You Clicked Item 2",Toast.LENGTH_LONG).show()
dialog.dismiss()
}
}
}
// create & show alert dialog
val dialog = builder.create()
dialog.show()
}
public static void EditTextListPicker(final Activity activity, final EditText EditTextItem, final String SelectTitle, final String[] SelectList) {
EditTextItem.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(SelectTitle);
builder.setItems(SelectList, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int item) {
EditTextItem.setText(SelectList[item]);
}
});
builder.create().show();
return false;
}
});
}