0
我試圖讓對話框彈出一個註釋列表,並在底部添加一個自己的選項。 (科西嘉的我想隱藏txtfirstComment是否有填充的列表,但我還沒有把它藏在尚未)使用ListView自定義對話框
Here'swhat我迄今所做:
public static Dialog openComments(Activity a) {
// custom dialog
final Dialog dialog = new Dialog(a);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.getWindow().getAttributes().windowAnimations = R.style.dialog_animation;
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.feed_comment);
String[] listItems = {"item 1", "item 2 ", "list", "android", "item 3", "foobar", "bar", };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(a, R.id.lstCommentList, android.R.id.text1, listItems);
setListAdapter(adapter);
return dialog;
}
繼承人的XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/dialog_background"
android:orientation="vertical" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical" >
<TextView
android:id="@+id/txtfirstComment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/nocomment"
android:background="#00000000"
android:gravity="center_horizontal"
android:textIsSelectable="false"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".1"
android:gravity="center_horizontal|center_vertical" >
<ListView
android:id="@+id/lstCommentList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<View
android:id="@+id/line1"
android:layout_width="wrap_content"
android:layout_height="1dip"
android:layout_marginTop="10dp"
android:background="@color/darkgrey"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical" >
<EditText
android:id="@+id/txtMakeComment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/makecomment"
android:background="#00000000"
android:gravity="center_horizontal" />
</LinearLayout>
</LinearLayout>
你的問題是什麼? –
請勿使用獨立對話框,而應使用「DialogFragment」。更多的優勢和更少擔心設備旋轉。 – gunar
這裏是一個很好的教程,你可以找到如果你谷歌「android自定義對話框」。 http://www.mkyong.com/android/android-custom-dialog-example/ – user666