Reputation: 2504
I'm trying to get a dialog to pop up with a list of comments, and at the bottom the option to add one yourself. (of corse i want to hide txtfirstComment if there is a list populated but i havent hid it yet)
Here'swhat I've done thus far:
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;
}
Heres' the 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>
Upvotes: 0
Views: 89
Reputation: 61
The ArrayAdapter second constructor arg you are passing the resource ID of the listview, whereas it should be the id of the layout (Android.R.layout.simple_list_item_1) which contains the textview (the third argument).
Also are you using ListActivity?
Upvotes: 1