0
Spinner를 사용하여 맞춤 알림 대화 상자를 만들고 싶습니다. 다음 코드를 사용했습니다. DialogAlert에 대한setContentView, android에서 스피너 맞춤 알림 대화 상자
AlertDialog.Builder alertDialog = new AlertDialog.Builder(ActivityThu.this);
alertDialog.setTitle("Thêm khoản thu");
//final LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// final View dialogView = layoutInflater.inflate(R.layout.thu_thong_bao_them, null);//Tạo dialogview từ layout thông báo
View dialogView = getLayoutInflater().inflate(R.layout.thu_thong_bao_them, null);
spinner=(Spinner)dialogView.findViewById(R.id.spdanhmuc_them);
MyDatabaseHelper db = new MyDatabaseHelper(getApplicationContext());
List<String> lables = db.Load_danhmucthu();
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, lables);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(dataAdapter);
alertDialog.setView(dialogView);// đặt dialogview vào alertdialog
alertDialog.setIcon(R.drawable.add48x48);//đặt icon
alertDialog.setPositiveButton("Thêm",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.setNegativeButton("Hủy",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertDialog.show();
레이아웃 제발 도와주세요
Image Befor I call AlertDialog
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Danh mục"
android:id="@+id/tvdanhmuc_them"/>
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/tvdanhmuc_them"
android:layout_marginLeft="20dp"
android:id="@+id/spdanhmuc_them"
android:spinnerMode="dropdown">
</Spinner>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nội dung"
android:id="@+id/tvnoidung_them"
android:layout_below="@+id/tvdanhmuc_them"
android:layout_marginTop="20dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<EditText
android:id="@+id/edtnoidung_them"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/tvnoidung_them"
android:layout_below="@id/spdanhmuc_them"
android:layout_marginLeft="20dp"
android:inputType="text" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ngày thu"
android:id="@+id/tvngaythu_them"
android:layout_below="@+id/tvnoidung_them"
android:layout_marginTop="20dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<EditText
android:id="@+id/edtngaythu_them"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:inputType="text"
android:layout_toRightOf="@id/tvnoidung_them"
android:layout_below="@id/edtnoidung_them"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Số tiền"
android:id="@+id/tvsotien_them"
android:layout_marginTop="20dp"
android:layout_below="@+id/tvngaythu_them"
/>
<EditText
android:id="@+id/edtsotien_them"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/tvsotien_them"
android:layout_below="@id/edtngaythu_them"
android:layout_marginLeft="30dp"
android:inputType="text" />
</RelativeLayout>
을 thu_thong_bao_them.xml.
감사를 아이콘처럼 대화와 관련된 아무것도 설정하지, 대화보기를 경고하도록 설정, 사용자 지정보기를 만들 수 있습니다. 아이콘, pos 단추를 제거한 후; alertdialog가 표시했지만 회 전자에 데이터가 없습니다. 그리고 몇 가지 기능을 수행하기 위해 버튼을 어떻게 추가 할 수 있습니까? Cancle, ..? – Chien
이미 경고 대화 상자 용 사용자 정의 레이아웃을 만들었습니다. 원하는 레이아웃으로 버튼을 추가 할 수 있습니다. –
도움 주셔서 감사합니다 :)) – Chien