I have some problem with Listview. Listview has list items that consist of imageview and textview. Textview contains clickable links. When I set LinkMovementMethod to textviews, listitems doesn`t receive onclick event. I still cannot find any right solution=(. Can anyone explane how to solve it or give an example of using textview with clickable links inside listitem? Thanks.
i tried to many ways but i couldnt do useful thins ! tank you for help . Here is textview creation in adapter:
TextView text = (TextView) ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.post_content_text, null);
SpannableString sString = new SpannableString(d.getText());
//I have my own class UrlSpan that contain fields startPosition, endPosition and urlLink
for (UrlSpan us : ((TextData) d).getUrls())
{
URLSpan urlSpan = new URLSpan(us.getUrl());
sString.setSpan(urlSpan, us.getStart(), us.getEnd(), SpannableString.SPAN_INCLUSIVE_INCLUSIVE);
}
text.setText(sString);
text.setMovementMethod(LinkMovementMethod.getInstance());
view.addView(text);
and list item is:
<?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:visibility="visible" >
<LinearLayout
style="?PostListRow"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="10dp"
android:orientation="vertical"
android:padding="10dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="65dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/user_image"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_margin="3dp"
android:clickable="true"
android:src="#drawable/ic_no_photo" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="55dp"
android:layout_margin="0dp"
android:orientation="vertical" >
<TextView
android:id="#+id/user_title"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:clickable="true"
android:textSize="#dimen/title_in_list" />
<TextView
android:id="#+id/post_datetime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:textSize="#dimen/text_size_small" />
</LinearLayout>
<TextView
android:id="#+id/post_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="123" />
</LinearLayout>
<!-- it is a view where textview with links is to be added to -->
<LinearLayout
android:id="#+id/post_data"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="6" >
</LinearLayout>
<TextView
android:id="#+id/post_view"
style="?PostText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:visibility="gone" />
<LinearLayout
android:id="#+id/topic_edit_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</LinearLayout>
</LinearLayout>
Related
Why does my textview automatically change the color to gray as if they were disabled when I add them programmatically? I am sure I did not set any color to gray in my layout.
Here's my code for adding textview programmatically:
LayoutInflater inflater = (LayoutInflater) getActivity().getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View chat = inflater.inflate(R.layout.chat_list_item, null);
((TextView)chat.findViewById(R.id.chat_name)).setText(obj.getString("username"));
LinearLayout container = (LinearLayout) getActivity().findViewById(R.id.chat_list);
container.addView(chat);
here is my layout item:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="10"
android:orientation="horizontal"
android:id="#+id/chat_view"
android:clickable="true"
>
<ImageView
android:layout_width="0dp"
android:layout_height="80dp"
android:layout_weight="2"
android:id="#+id/chat_propic"
android:scaleType="fitCenter"
android:src="#drawable/face"
/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="8"
android:paddingLeft="10dp"
android:weightSum="3"
android:orientation="vertical"
>
<!-- name and last message-->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="10"
android:orientation="horizontal"
>
<TextView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="7"
android:gravity="bottom"
android:id="#+id/chat_name"
android:text="UserNAMEEEE"
android:textStyle="bold"
/>
<TextView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="3"
android:gravity="bottom"
android:id="#+id/chat_time"
android:text="30/05/2015"
/>
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:gravity="center|left"
android:id="#+id/chat_message"
android:text="asjkdgaksgkdagskdakjsdhklahskld"
/>
<View
android:layout_height="1dp"
android:layout_width="fill_parent"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="#ff828282"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
You can add a line after creating the TextView
chat.setTextAppearance(context, android.R.style.TextAppearance_DeviceDefault);
Might not work but I remember my friend having a problem similar to this and I told him this: "activate" the textView.
chat.setActivated(TRUE);
The "TRUE" might be wrong, there might be something like View.ACTIVATED or so ,test it out yourself please :)
Let me know if you need anything else and if it worked.
I need to arrange two ListViews in a vertical LinearLayout in such a way that 2nd ListView will be at the end of last item of first ListView.
If ListView1 is empty, the view should be something like this.
As ListView1.size() increases ListView2 should be pulled down to a limit.
ListView1 reaches a fixed height (or weight) , it should stop expanding and start scrolling.
I think there is no method in android to set maxHeight for View.
I have already tried almost all combinations of layout_height="wrap_content", fixed heights and weights for both ListViews. In all cases,
either 1st requirement(image1) will fail : ListView1 will not be at top
or last requirement(image3) will fail : ListView2 will get pushed out of the screen.
Any help or suggestions will be appreciated. Thanks in advance.
Edit:
my current code is:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1" >
<ListView
android:id="#+id/myOrderListView"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.6" >
</ListView>
<ListView
android:id="#+id/myCompletedOrderListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_weight="0.4" >
</ListView>
</LinearLayout>
I have tried with different weight combinations, like:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1" >
<ListView
android:id="#+id/myOrderListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.6" >
</ListView>
<ListView
android:id="#+id/myCompletedOrderListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_weight="0.4" >
</ListView>
</LinearLayout>
But it will fail last requirement.
Edit2: #dangVarmit
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1" >
<ListView
android:id="#+id/myOrderListView"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
<ListView
android:id="#+id/myCompletedOrderListView"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="20dp" >
</ListView>
<Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
If you mean this, It still fails req3.
You can find the below code for right and left listview you can change it to above and bottom listview or as you want to show
main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/main_top_bit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/orange">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:orientation="horizontal">
<Button
android:id="#+id/button_1"
style="#style/landscape_top_button"
android:text="button1" />
<Button
android:id="#+id/button_2"
style="#style/landscape_top_button"
android:text="button2"/>
</LinearLayout>
</LinearLayout>
<View android:id="#+id/main_horizontal_bar"
android:layout_height="3dip" android:layout_width="fill_parent"
android:background="#color/gray" android:layout_marginTop="1dip" />
</LinearLayout>
<LinearLayout
android:id="#+id/lower_linear_layout"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/main_top_bit">
<RelativeLayout
android:layout_below="#+id/lower_linear_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="150dip"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#color/teal"
android:id="#+id/org_left_linearlayout2">
<Button
android:id="#+id/button_3"
style="#style/landscape_top_button"
android:text="button3"/>
<Button
android:id="#+id/button_4"
style="#style/landscape_top_button"
android:text="button4" />
</LinearLayout>
<ListView
android:background="#color/green"
android:id="#+id/lstLeft"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/org_left_linearlayout2"
android:layout_above="#+id/org_left_bottom_rl"
android:cacheColorHint="#00000000"/>
<RelativeLayout
android:id="#+id/org_left_bottom_rl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/purple" >
<Button
android:text="button5"
android:id="#+id/button_5"
android:layout_alignParentLeft="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
</RelativeLayout>
</RelativeLayout>
<View
android:layout_width="3dip"
android:layout_height="fill_parent"
android:background="#color/gray">
</View>
<RelativeLayout
android:layout_below="#+id/lower_linear_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#color/olive"
android:id="#+id/org_right_linearlayout2">
<Button
android:id="#+id/button_6"
style="#style/landscape_top_button"
android:text="button6" />
<Button
android:id="#+id/button_7"
style="#style/landscape_top_button"
android:text="button7" />
</LinearLayout>
<ListView
android:id="#+id/lstRight"
android:background="#color/blue"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/org_right_linearlayout2"
android:layout_above="#+id/org_right_bottom_rl"
android:cacheColorHint="#00000000"/>
<RelativeLayout
android:id="#+id/org_right_bottom_rl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/red"
android:layout_alignParentBottom="true">
<Button
android:text="button8"
android:id="#+id/button_8"
android:layout_alignParentRight="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
MainActivity.java
public class MainActivity extends Activity {
private final String TAG = this.getClass().getName();
ListView leftList;
ListView rightList;
static final String[] FRUITS = new String[] {"Apple", "Bananna", "Cherry", "Pear", "Strawberry"};
static final String[] VEGETABLES = new String[] {"Asparagus", "Bamboo shoots", "Celery", "Ginger", "Spinach"};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
leftList = (ListView) findViewById(R.id.lstLeft);
rightList = (ListView) findViewById(R.id.lstRight);
populateLeftList();
populateRightList();
}
public void populateLeftList(){
leftList.setAdapter(new ArrayAdapter<string>(this, android.R.layout.simple_list_item_1, FRUITS));
}
public void populateRightList(){
rightList.setAdapter(new ArrayAdapter<string>(this, android.R.layout.simple_list_item_1, VEGETABLES));
}
}
for list1, layout_height=wrap_content, remove layout_weight
for list2, layout_height=100dp (any fixed value), remove layout_weight
add <Space layout_weight=1 layout_height=0dp/> at the end of the list.
that should give you the results you are looking for.
I have found one solution by myself. It works perfectly as i wanted. I dont know whether it is a good approach or not. I am searching for an xml solution.
getDeviceHeight() is my method to find device height in pixels.
200 is the approximate height of other ui elements above My ListViews.
myorderList is my first ListView
if(myorderList.getHeight() > ((getDeviceHeight()/2) - 200)) {
LayoutParams params = myorderList.getLayoutParams();
params.height = (int)((getDeviceHeight()/2) - 200);
myorderList.setLayoutParams(params);
}
This should be done when there is any kind of changes happening to the first ListView.
Edit:
This will also fail when items removed after reaching maximum height :-(
In my first screen shot you can see expended listview at top and textview placed at below next to expended listview.
But if you look at my second screen shot, as the listview adds more items textview place at the bottom does not appear.
My layout code is :
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/form_view"
>
<LinearLayout
android:id="#+id/relativeLayout1"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Spinner
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="2"
android:id="#+id/spinnerSemester" />
<Button
android:id="#+id/graph_button"
android:layout_width="0dip"
android:layout_weight="0.7"
android:layout_height="wrap_content"
android:text="Chart" />
</LinearLayout>
<ExpandableListView
android:id="#+id/lv_attendance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_weight="1"
android:cacheColorHint="#00000000"
>
</ExpandableListView>
<TextView
android:id="#+id/TV_note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/lv_attendance"
android:paddingLeft="10dp"
android:text="[NOTE : The data displayed here is for advance information only. Please check with the college office/department concerned for the final and certified data. In case of discrepancies, the data maintained in the college records will be deemed to be the final one.]"
android:layout_marginTop="10px"
android:textSize="13sp" />
</LinearLayout>
Thanks,
Nandakishore P
Try as below...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/form_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Spinner
android:id="#+id/spinnerSemester"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="2" />
<Button
android:id="#+id/graph_button"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:text="Chart" />
</LinearLayout>
<ExpandableListView
android:id="#+id/lv_attendance"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:cacheColorHint="#00000000" >
</ExpandableListView>
<TextView
android:id="#+id/TV_note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:paddingLeft="10dp"
android:text="[NOTE : The data displayed here is for advance information only. Please check with the college office/department concerned for the final and certified data. In case of discrepancies, the data maintained in the college records will be deemed to be the final one.]"
android:textSize="13sp" />
</LinearLayout>
consider specifyig android:layout_weight to the views, also encasing that text view in a framelayout or linearlayout
Gods, I hate layout...
Dont use android:layout_below="#+id/lv_attendance", its creating problem, use alignParentBottom instead.
I have some problem with Listview. Listview has list items that consist of imageview and textview. Textview contains clickable links. When I set LinkMovementMethod to textviews, listitems doesn`t receive onclick event. I still cannot find any right solution=(. Can anyone explane how to solve it or give an example of using textview with clickable links inside listitem? Thanks.
Here is textview creation in adapter:
TextView text = (TextView) ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.post_content_text, null);
SpannableString sString = new SpannableString(d.getText());
//I have my own class UrlSpan that contain fields startPosition, endPosition and urlLink
for (UrlSpan us : ((TextData) d).getUrls())
{
URLSpan urlSpan = new URLSpan(us.getUrl());
sString.setSpan(urlSpan, us.getStart(), us.getEnd(), SpannableString.SPAN_INCLUSIVE_INCLUSIVE);
}
text.setText(sString);
text.setMovementMethod(LinkMovementMethod.getInstance());
view.addView(text);
and list item is:
<?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:visibility="visible" >
<LinearLayout
style="?PostListRow"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="10dp"
android:orientation="vertical"
android:padding="10dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="65dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/user_image"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_margin="3dp"
android:clickable="true"
android:src="#drawable/ic_no_photo" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="55dp"
android:layout_margin="0dp"
android:orientation="vertical" >
<TextView
android:id="#+id/user_title"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:clickable="true"
android:textSize="#dimen/title_in_list" />
<TextView
android:id="#+id/post_datetime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:textSize="#dimen/text_size_small" />
</LinearLayout>
<TextView
android:id="#+id/post_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="123" />
</LinearLayout>
<!-- it is a view where textview with links is to be added to -->
<LinearLayout
android:id="#+id/post_data"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="6" >
</LinearLayout>
<TextView
android:id="#+id/post_view"
style="?PostText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:visibility="gone" />
<LinearLayout
android:id="#+id/topic_edit_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</LinearLayout>
</LinearLayout>
try to add this attribute
android:descendantFocusability="beforeDescendants"
to your listview
from the documentation:
it defines the relationship between the ViewGroup and its descendants when looking for a View to take focus. it seems to me that when you have some active views like buttons or edittext and etc in your listview you have to define descendantFocusability
I have this pretty basic view:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="#+id/question_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Your question: "
/>
<TextView
android:id="#+id/question"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
<EditText
android:id="#+id/question_text"
android:layout_height="wrap_content"
android:hint="#string/question_comment_hint"
android:inputType="textMultiLine"
android:lines="4"
android:layout_width="fill_parent">
</EditText>
<Button
android:id="#+id/submit"
android:layout_height="wrap_content"
android:text="#string/submit"
android:onClick="sendFeedback"
android:layout_width="fill_parent">
</Button>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/please_wait"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Please wait while the discussion loads..."
/>
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#+id/label"
android:textSize="20px" >
</ListView>
</LinearLayout>
</ScrollView>
</LinearLayout>
What I was hoping to do with it is to allow the user to scroll through the entire list of comments. As of now, when there are more comments then space on the screen, the screen does not scroll down.
Any idea what I should change to enable scrolling of the comments?
Thanks!
I would do away with the scrollview completely - based on what I THINK you're try to accomplish, since the listview will handle scrolling on its own. Like such:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="#+id/question_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Your question: "
/>
<TextView
android:id="#+id/question"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
<EditText
android:id="#+id/question_text"
android:layout_height="wrap_content"
android:hint="#string/question_comment_hint"
android:inputType="textMultiLine"
android:lines="4"
android:layout_width="fill_parent">
</EditText>
<Button
android:id="#+id/submit"
android:layout_height="wrap_content"
android:text="#string/submit"
android:onClick="sendFeedback"
android:layout_width="fill_parent">
</Button>
<TextView
android:id="#+id/please_wait"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Please wait while the discussion loads..."
/>
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#+id/label"
android:textSize="20px" >
</ListView>
The difference now, is that the TextView with id "please_wait" will not scroll with the list. If you need it to scroll with the list, I would recommend using a dynamically built TableLayout in java for your list, then add that and your textview to a ScrollView. The TableLayout doesn't scroll on its own, and thats why its a better solution than using a ListView inside a ScrollView. If you want to do it this way, let me know and I will post some example code.
Seems like you're trying to add a header above your comments in the ListView. As coder noted, you shouldn't put a ListView in a ScrollView. You should look at adding a header view directly to your ListView (see addHeaderView).
basicly you can do like this:
get rid of scrollview and loading textview.
set a simple adaptor to your listview like this:
fList = (ListView)findViewById(R.id.lstview);
fList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new String[]{"Please wait while the discussion loads..."}));
Than get your comments and set to your listview.
list.setAdapter(adapter);
You should not have a ListView inside a ScrollView.
inflate a LinearLayout(vertical) instead:
<?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:orientation="vertical" >
<TextView
android:id="#+id/question_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Your question: " />
<TextView
android:id="#+id/question"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="" />
<EditText
android:id="#+id/question_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/question_comment_hint"
android:inputType="textMultiLine"
android:lines="4" >
</EditText>
<Button
android:id="#+id/submit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="sendFeedback"
android:text="#string/submit" >
</Button>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/please_wait"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Please wait while the discussion loads..." />
<LinearLayout
android:id="#+id/comments_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
In your code:
LinearLayout commentsLayout = (LinearLayout) findViewById(R.id.comments_layout);
To populate the LinearLayout:
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for(int i = 0; i < comments.size(); i++){
View childView = inflater.inflate(R.layout.comment_list_item, commentsLayout, false);
TextView comment = (TextView) childView.findViewById(R.id.comment);
comment.setText("Something");
categoriesLayout.addView(childView, i);
}
Something like that, hope this helps.