2012-08-10 49 views
2

enter image description hereAndroid的如何添加網格視圖列表視圖的頁腳

我有我要在列表視圖中添加頁腳,因爲我想要這個頁面應該有完整的頁面滾動功能,一個網格視圖。

這裏是我的代碼我在哪裏設置我的網格視圖和我的網格視圖適配器,但是它的顯示footer.i空白有兩種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; 
    } 

} 

GallaryLoginMainActivity

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(); 
    } 


} 

回答

2

終於我有我自己的問題的答案我已經創造了新的適配器採用Android查詢庫,並實施了新的網格視圖適配器我的屏幕,發現在滾動視圖更平滑偉大的結果...

這裏是我的代碼

public class GalleryMainActivityGridViewAdapter extends BaseAdapter { 

    AQuery listAQ; 
    Context mContext; 
    int layoutResourceId; 
    ArrayList<HashMap<String, String>> dataArray; 

    public GalleryMainActivityGridViewAdapter(Context context, ArrayList<HashMap<String, String>> resultArray) { 
     this.mContext = context; 
     // this.layoutResourceId = layoutId; 
     this.dataArray = resultArray; 
     listAQ = new AQuery(mContext); 
     // aa = new ArrayAdapter<Photo>(mContext, layoutResourceId); 
    } 

    public int getCount() { 
     return dataArray.size(); 
    } 

    public Object getItem(int position) { 
     return position; 
    } 

    public long getItemId(int position) { 
     return 0; 
    } 

    @SuppressWarnings("deprecation") 
    public View getView(int position, View convertView, ViewGroup parent) { 

     if (convertView == null) { 
      convertView = ((LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.gallery_main_page_grid_item, parent, false); 
     } 
     Holder holder = new Holder(); 

     AQuery aq = listAQ.recycle(convertView); 

     holder.imgView_Grid_Thumbnail_Gallery = (ImageView) convertView.findViewById(R.id.imgView_Grid_Thumbnail_Gallery); 

     if (holder.imgView_Grid_Thumbnail_Gallery != null) { 
      aq.id(holder.imgView_Grid_Thumbnail_Gallery.getId()).image(dataArray.get(position).get("thumbUrl") + "/11"); 
     } 

     holder.txtView_Grid_Name_Gallery = (TextView) convertView.findViewById(R.id.txtView_Grid_Name_Gallery); 
     if (holder.txtView_Grid_Name_Gallery != null) { 
      aq.id(holder.txtView_Grid_Name_Gallery.getId()).text(dataArray.get(position).get("user_name")); 
      Typeface txtViewForName = Typeface.createFromAsset(convertView.getContext().getAssets(), "fonts/arial_bold.ttf"); 
      holder.txtView_Grid_Name_Gallery.setTypeface(txtViewForName); 

     } 

     holder.imgView_GridItem_Gallery = (ImageView) convertView.findViewById(R.id.imgView_GridItem_Gallery); 

     if (holder.imgView_GridItem_Gallery != null) { 

      Bitmap cachedImage = aq.getCachedImage(R.drawable.loading); 
      String publicUrl = dataArray.get(position).get("publicUrl") + "/13"; 
      if (aq.shouldDelay(convertView, parent, publicUrl, 0)) { 
       aq.id(holder.imgView_GridItem_Gallery.getId()).image(cachedImage, 0.75f); 
      } else { 
       aq.id(holder.imgView_GridItem_Gallery.getId()).image(publicUrl, true, true, 0, 0, cachedImage, 0, 0.75f); 
      } 
     } 

     // if (holder.txtView_Grid_Views_Gallery != null) { 
     // 
     // } 
     holder.imgView_Grid_PlayVideo = (ImageView) convertView.findViewById(R.id.imgView_Grid_PlayVideo); 
     if (holder.imgView_Grid_PlayVideo != null) { 

      if (dataArray.get(position).get("filetype").toString().equals("1")) { 
       holder.imgView_Grid_PlayVideo.setVisibility(View.GONE); 
      } else { 
       holder.imgView_Grid_PlayVideo.setVisibility(View.VISIBLE); 
      } 
     } 

     return convertView; 

    } 

    class Holder { 
     ImageView imgView_Grid_PlayVideo; 
     ImageView imgView_Grid_Thumbnail_Gallery; 
     TextView txtView_Grid_Views_Gallery; 
     TextView txtView_Grid_Name_Gallery; 
     ImageView imgView_GridItem_Gallery; 
    } 

} 
相關問題