Trying To Achieve
- Add Button After GridView which has
layout_height="wrap_parent"&layout_width="fill_parent"to provide better UIx.
Constraints:
Adding ImageViews which fetched from Facebook-Graph-Api to GridView which consists of ImageView.
Add Button atlast of GridView once the Image's fetched.
Tried
1. Setting Visibility of Button to Visible at onPostExecute() of AysncTask which helps me to fetched the Image's
2. Setting Visibility of Button to Visible at ScrollListener which would run if it Scrolling reaches end of GridView i.e Last Image inside GridView
But Button is not showing at the end of GridView. Dunno Why??
My XML Layout::
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="@+id/rootview"
>
<Button
android:id="@+id/fbconnect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/connectfb"
android:layout_centerHorizontal="true"
android:visibility="visible"
/>
<GridView
android:id="@+id/gridphoto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:columnWidth="80dp"
android:numColumns="auto_fit"
android:verticalSpacing="2dp"
android:horizontalSpacing="2dp"
android:stretchMode="columnWidth"
/>
<Button
android:id="@+id/loadmore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/gridphoto"
android:visibility="gone"
android:text="@string/load_more"
/>
</RelativeLayout>
Code :: Fetching Images via AysncTask and Setting Visibility at onPostExecute to add LoadMore Button at end of GridView.
protected void onPostExecute(Void result) {
loadMore.setVisibility(View.VISIBLE); // Load More Button
}
Code :: Implementing ScrollListener on GridView -- > Checking If it reaches bottom or not then changing Visibility of Load More button.
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (gridView.getLastVisiblePosition() + 1 == increasingItem) // Checking if it reaches bottom of GridView or not. It prefectly runs. Checked via Logging into StackTrace.
{
loadMore.setVisibility(View.VISIBLE); // Load More Button
}
}