I have a gridview
which I am inflating with a relativelayout
. Consider this as an example of the layout:
0 1 2
3 4 5
......
......
I have a progress bar
in the layout, that I want to apply only to the layout at position 0. And update it using an async task
after the adapter is set. Ofcourse with gridview I cannot just access view at position 0 and show/hide progressbar
whenever it gets rendered again. What should I do in order to fix the layout of the first child of the gridview and do not let it change whenever the user scrolls through the items?
This is my method of getView()
:
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
convertView = inflater.inflate(R.layout.gridview_tvguide, null);
holder = new ViewHolder();
holder.image = (ImageButton) convertView.findViewById(R.id.image);
holder.showTitle = (TextView) convertView
.findViewById(R.id.ShowTitle);
holder.showDuration = (TextView) convertView
.findViewById(R.id.ShowTime);
//by default visibility is set to GONE
holder.progBar = (ProgressBar) convertView.findViewById(R.id.progressBar);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
//logic to control the progressbar from asynctask
if (this.updateNowPlaying){
holder.progBar.setProgress(this.progress);
return convertView;
}
ImageLoader.getInstance().displayImage(
this.shows.get(position).getShowThumb(), holder.image);
holder.showTitle.setText(this.shows.get(position).getShowTitle());
holder.showDuration.setText(this.shows.get(position).getShowTime());
return convertView;
}
EDIT
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rlImage"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:paddingBottom="7dp"
android:paddingRight="7dp" >
<ImageButton
android:id="@+id/image"
android:layout_width="220dp"
android:layout_height="220dp"
android:adjustViewBounds="true"
android:background="@null"
android:scaleType="centerCrop"
android:src="@drawable/noimage" />
<ImageButton
android:id="@+id/imageHover"
android:layout_width="220dp"
android:layout_height="220dp"
android:adjustViewBounds="true"
android:background="@null"
android:scaleType="fitXY"
android:src="@drawable/tile_selector_style" />
<TextView
android:id="@+id/ShowTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:hint="Show Title"
android:paddingBottom="40dp"
android:paddingRight="20dp"
android:singleLine="true" />
<TextView
android:id="@+id/ShowTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:hint="Show Time"
android:paddingBottom="20dp"
android:paddingRight="20dp"
android:singleLine="true" />
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:visibility="gone"
android:layout_margin="0dp" />
</RelativeLayout>
This is my gridview
:
<GridView
android:id="@+id/gridView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:clipToPadding="true"
android:columnWidth="200dp"
android:fitsSystemWindows="true"
android:layout_weight="1"
android:numColumns="auto_fit"
android:stretchMode="columnWidth" >
</GridView>
to show the progress bar only for item 0
add this code after if/else
initializing your holder :
if (position == 0) {
holder.progBar.setVisibility(View.VISIBLE);
} else {
holder.progBar.setVisibility(View.GONE);
}