Reputation: 639
I'm relatively new to Android dev so please pardon me if this is a basic question. I have a ListActivity which shows a progress bar when loading info and then gets hidden. However, every row of the listview beneath it draws has its own progressbar in it. How can I prevent this from happening? I've found a few somewhat similar questions but no working answer. EDIT: This is resultslist.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="6dip">
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/results_list_progress_bar"/>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_below="@id/results_list_progress_bar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<ImageView
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:id="@+id/result_icon"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginRight="6dip"
android:contentDescription="TODO" />
<TextView
android:id="@+id/result_title"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/result_icon"
android:ellipsize="marquee"
android:singleLine="true"
android:textSize="12sp"
/>
<TextView
android:id="@+id/result_description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/result_title"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:layout_toRightOf="@id/result_icon"
android:gravity="center_vertical"
android:singleLine="true"
android:textSize="12sp"
/>
</LinearLayout>
for what it's worth, here's the code from my array adapter:
LayoutInflater inflater = (LayoutInflater)context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.resultslist, parent, false);
Here's an image, showing the progress bar at the top of each row:
Any help would be greatly appreciated! Thanks!
Upvotes: 0
Views: 175
Reputation: 10223
It looks like what you are doing is inflating the same layout for your ListView
as you are for your activity. What that means is that every item in your ListView
will have a ProgressBar
and a ListView
in addition to all the other things you want. What you should do is move these items:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="6dip">
<ImageView
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:id="@+id/result_icon"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginRight="6dip"
android:contentDescription="TODO" />
<TextView
android:id="@+id/result_title"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/result_icon"
android:ellipsize="marquee"
android:singleLine="true"
android:textSize="12sp"
/>
<TextView
android:id="@+id/result_description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/result_title"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:layout_toRightOf="@id/result_icon"
android:gravity="center_vertical"
android:singleLine="true"
android:textSize="12sp"
/>
</LinearLayout>
into a new layout, let's call it listviewlayout.xml
. Then you change your code in your activity to this:
LayoutInflater inflater = (LayoutInflater)context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.listviewlayout, parent, false);
And then you keep the other stuff in your first layout.
Upvotes: 1
Reputation: 3288
I believe you are inflating the same activity view
as your list item view
, check your view for the adapter
as of your update, it is visible that your are in fact inflating the same view
solution:
your main xml view (put this inside a linear layout):
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/results_list_progress_bar"/>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_below="@id/results_list_progress_bar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
your list item view (put this inside a linear layout):
<ImageView
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:id="@+id/result_icon"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginRight="6dip"
android:contentDescription="TODO" />
<TextView
android:id="@+id/result_title"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/result_icon"
android:ellipsize="marquee"
android:singleLine="true"
android:textSize="12sp"
/>
<TextView
android:id="@+id/result_description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/result_title"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:layout_toRightOf="@id/result_icon"
android:gravity="center_vertical"
android:singleLine="true"
android:textSize="12sp"
/>
Upvotes: 2