我有一个网格视图,我想在列表视图的页脚中添加它,因为我希望这个页面应该具有整页滚动功能。
这是我的代码,我正在使用我的网格视图适配器设置我的网格视图,但它在页脚中显示为空白。我有两个 xml,一个用于标题,另一个仅用于网格视图。
GalleryGridViewAdapter
public class GalleryMainActivityGridViewAdapter extends BaseAdapter {
/**
* Description:Declare the UI components.
*/
private Context mContextGridView;
private GallerySmartLazyLoader sl;
ArrayList<HashMap<String, String>> galleryArray;
/**
* This method is use to set object that will control the listview
*
* @param c
* @param resultArray
*
*/
public GalleryMainActivityGridViewAdapter(Context c, ArrayList<HashMap<String,String>>
resultArray) {
mContextGridView = c;
galleryArray = new ArrayList<HashMap<String, String>>();
galleryArray = resultArray;
sl = new GallerySmartLazyLoader(mContextGridView);
}
public int getCount() {
return galleryArray.size();
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
/**
* Description:This method returns a bitmap related to drawable.
*
* @param bitmapUrl
* to set the background on detail page
*
*/
public Bitmap getBitmap(String bitmapUrl) {
URL url;
try {
System.out.println("bitmapUrl :" + " bitmapUrl : " + bitmapUrl);
url = new URL(bitmapUrl);
return BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
// create View for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
View MyView = convertView;
if (convertView == null) {
/* create a new view of our layout and inflate it in the row */
// Inflate the layout
LayoutInflater inflater = (LayoutInflater) mContextGridView.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
MyView = inflater.inflate(R.layout.gallery_main_page_grid_item, null);
// Initialize the UI components
ImageView imgView_Grid_PlayVideo = (ImageView) MyView.findViewById(R.id.imgView_Grid_PlayVideo);
ImageView imgView_Grid_Thumbnail_Gallery = (ImageView) MyView.findViewById(R.id.imgView_Grid_Thumbnail_Gallery);
TextView txtView_Grid_Views_Gallery = (TextView) MyView.findViewById(R.id.txtView_Grid_Views_Gallery);
Typeface txtViewForViews = Typeface.createFromAsset(MyView.getContext().getAssets(), "fonts/arial.ttf");
txtView_Grid_Views_Gallery.setTypeface(txtViewForViews);
TextView txtView_Grid_Name_Gallery = (TextView) MyView.findViewById(R.id.txtView_Grid_Name_Gallery);
Typeface txtViewForName = Typeface.createFromAsset(MyView.getContext().getAssets(), "fonts/arial_bold.ttf");
txtView_Grid_Views_Gallery.setTypeface(txtViewForName);
ImageView imgView_GridItem_Gallery = (ImageView) MyView.findViewById(R.id.imgView_GridItem_Gallery);
// This will set the item coming from API
imgView_Grid_Thumbnail_Gallery.setImageBitmap(getBitmap(galleryArray.get(0).get("publicUrl") + "/11"));
txtView_Grid_Views_Gallery.setText(galleryArray.get(position).get("hits") + " views");
txtView_Grid_Name_Gallery.setText(galleryArray.get(position).get("user_name"));
imgView_GridItem_Gallery.setScaleType(ImageView.ScaleType.FIT_XY);
imgView_GridItem_Gallery.setPadding(0, 0, 0, 0);
String url = galleryArray.get(position).get("thumbUrl") + "/13";
imgView_GridItem_Gallery.setTag(url);
sl.DisplayImage(url, (Activity) mContextGridView, imgView_GridItem_Gallery);
if (galleryArray.get(position).get("filetype").toString().equals("1")) {
imgView_Grid_PlayVideo.setVisibility(View.GONE);
} else {
imgView_Grid_PlayVideo.setVisibility(View.VISIBLE);
}
}
return MyView;
}
}
图库登录MainActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallary_login_main_page_list);
data = new ArrayList<ArrayList<HashMap<String, String>>>();
lstGallaryMain = (ListView) findViewById(R.id.lstGallaryMain);
inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
init(this, R.id.main, getIntent());
if (!Connection()) {
Context context = getApplicationContext();
CharSequence text = "Sorry you need an Internet connection! Please try again when the network is available.";
Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
toast.show();
finish();
} else {
/*
*
* This method is used to Show The loading dialog till the data
* loads for main page.
*/
new AsyncTask<Void, Void, Void>() {
protected void onPreExecute() {
loadingDialog = ProgressDialog.show(GallaryLoginMainActivity.this, getResources().getString(R.string.app_name), "Loading...");
}
@Override
protected Void doInBackground(Void... params) {
loadDataFromServer();
return null;
};
protected void onPostExecute(Void result) {
View footerView = inflater.inflate(R.layout.test_media, null);
GalleryMainActivityGridViewAdapter galleryMainActivityGridViewAdapter = new GalleryMainActivityGridViewAdapter(GallaryLoginMainActivity.this,userDataActivity);
GridView gridView = (GridView)footerView.findViewById(R.id.gridview_Gallery);
gridView.setAdapter(galleryMainActivityGridViewAdapter);
lstGallaryMain.addFooterView(gridView);
((GalleryMainActivityGridViewAdapter)(galleryMainActivityGridViewAdapter)).notifyDataSetChanged();
lstGallaryMain.setAdapter(new GalleryCustomAdapterForMainPage<T>(GallaryLoginMainActivity.this, data));
((BaseAdapter)(lstGallaryMain.getAdapter())).notifyDataSetChanged();
lstGallaryMain.addFooterView(gridView);
GallaryLoginMainActivity.this.onContentChanged();
if (loadingDialog != null && loadingDialog.isShowing()) {
loadingDialog.dismiss();
}
};
}.execute();
}
}