2013-10-11 46 views
0

我使用https://github.com/bulletnoid/StaggeredGridView這個庫來製作pinterest風格的佈局,並在此佈局上使用pulltorefresh。 ı有一個滑動菜單可供選擇不同的類別,並根據用戶選擇的類別,刷新並再次填充。StaggeredGridView只能正確刷新頂部

Pulltorefresh工作正常。

如果用戶頂部的佈局和選擇幻燈片菜單上的類別它的工作正常。但是,如果用戶在佈局的底部並在幻燈片菜單上選擇一個類別,它的工作就不正確。

場景,頂部佈局和選擇類別的幻燈片菜單和填充交錯佈局。它的正常工作

Top of the layout enter image description here

的情況下,對slidemenu佈局和選擇類別的底部和填充交錯的佈局。它無法正常工作

bottom of the layout enter image description here

- > listviewAdapter

public void onItemClick(AdapterView<?> parent, View view, int position, 
      long arg3) { 
     // TODO Auto-generated method stub 

     switch (parent.getId()) { 
     case R.id.listView_sliding_menu: 

      smenu.toggle(); 

      slidingMenuControl = true; 
      String categoryId = ((TextView) view.findViewById(R.id.categoryID)) 
        .getText().toString(); 

      parameters[0] = categoryId; 
      Toast.makeText(getApplicationContext(), categoryId, 
        Toast.LENGTH_LONG).show(); 
      new PARSEJSONCATEGORYCONTENT().execute(parameters); 

      break; 

     default: 
      break; 

     } 

    } 

- >解析器

private class PARSEJSONCATEGORYCONTENT extends 
       AsyncTask<String[], Void, ArrayList<Utils>> { 

      @Override 
      protected void onPreExecute() { 
       super.onPreExecute(); 
       processDialoge(); 
      } 

      protected ArrayList<Utils> doInBackground(String[]... params) { 

       String catId = params[0][0]; 
       String startCount = params[0][5]; 
       String count = params[0][6]; 
       String urlCatContent = "http://212.58.8.109/webservice/api/content/cat/"; 

       jArray = jsonParser.getJSONFromUrltoCategoryContent(urlCatContent, 
         Token, tokenValue, catId, startCount, count); 

       if (utilsArray == null) { 
        utilsArray = new ArrayList<Utils>(); 

       } else if (slidingMenuControl == true) { 

        utilsArray.clear(); 

       } else if (contentItemSelection != null) { 
        utilsArray.clear(); 
       } 

       try { 

        // looping through All Contacts 
        for (int i = 0; i < jArray.length(); i++) { 
         JSONObject k = jArray.getJSONObject(i); 
         utils = new Utils(); 

         // Storing each json item in variable 
         utils.imageUrl = k.getString("ipad_URL"); 
         utils.imageWidth = k.getInt("ipad_width"); 
         utils.imageHeight = k.getInt("ipad_height"); 
         utils.categoryHeader = k.getString("contentHeader"); 
         utils.contentDesc = k.getString("contentDesc"); 
         utils.categoryContentId = k.getInt("id"); 
         utils.contentTxt = k.getString("contentTxt"); 

         Log.d("ipad_URL", utils.imageUrl); 

         utilsArray.add(utils); 

        } 

        String arrayLenght = Integer.toString(utilsArray.size()); 
        Log.d("arrayLenght", arrayLenght); 

       } catch (JSONException e) { 
        e.printStackTrace(); 
       } 

       return utilsArray; 
      } 

      protected void onPostExecute(ArrayList<Utils> utilsArray) { 

       staggeredAdapter.getMoreItemm(utilsArray); 

       // staggeredAdapter.setRefreshListener(false); 
       super.onPostExecute(utilsArray); 
       slidingMenuControl = false; 
       dialog.cancel(); 
      } 

     } 

- > BaseAdapter.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN) 
@SuppressLint("NewApi") 
public class StaggeredAdapter extends BaseAdapter implements OnClickListener { 

    Typeface tf; 
    boolean refreshListener = false; 
    Utils utils; 

    private Context mContext; 
    private Application mAppContext; 
    private ArrayList<Utils> mUtilsArraylist = new ArrayList<Utils>(); 

    public StaggeredAdapter(Context context, Application application) { 

     mContext = context; 
     mAppContext = application; 
     tf = Typeface.createFromAsset(mContext.getAssets(), 
       "font/Klavika-Medium.otf"); 
     notifyDataSetChanged(); 

    } 

    public void getMoreItemm(ArrayList<Utils> arrayList) { 
     mUtilsArraylist.clear(); 
     mUtilsArraylist.addAll(arrayList); 
     this.notifyDataSetChanged(); 
    } 

    public int getCount() { 

     return mUtilsArraylist == null ? 0 : mUtilsArraylist.size(); 
    } 

    @Override 
    public Object getItem(int position) { 
     return mUtilsArraylist.get(position); 
    } 

    @Override 
    public long getItemId(int position) { 
     return mUtilsArraylist.indexOf(getItem(position)); 
    } 

    @SuppressLint("NewApi") 
    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 

     View view = null; 
     utils = mUtilsArraylist.get(position); 

     if (convertView == null) { 
      Holder holder = new Holder(); 
      view = View.inflate(mContext, R.layout.staggered_item, null); 

      holder.imgUrl_content = (STGVImageView) view 
        .findViewById(R.id.imgUrl_content); 

      holder.tv_info = (TextView) view.findViewById(R.id.contentHeader); 
      holder.tv_info.setTypeface(tf); 

      holder.tv_info2 = (TextView) view.findViewById(R.id.contentDesc); 
      holder.tv_info2.setTypeface(tf); 

      view.setTag(holder); 
     } else { 

      return convertView; 
     } 

     final Holder holder = (Holder) view.getTag(); 

     holder.imgUrl_content.mHeight = utils.imageHeight; 
     holder.imgUrl_content.mWidth = utils.imageWidth; 
     holder.imgUrl_content.setOnClickListener(this); 

     ImageLoader imgLoader = new ImageLoader(mAppContext); 
     imgLoader.DisplayImage(utils.imageUrl, holder.imgUrl_content); 

     holder.tv_info.setText(utils.categoryHeader); 
     holder.tv_info.setOnClickListener(this); 
     holder.tv_info2.setText(utils.contentDesc); 
     holder.tv_info2.setOnClickListener(this); 

     return view; 
    } 

    class Holder { 
     public STGVImageView imgUrl_content; 
     public TextView tv_info; 
     public TextView tv_info2; 

    } 

    public boolean isRefreshListener() { 
     return refreshListener; 
    } 

    public void setRefreshListener(boolean refreshListener) { 
     this.refreshListener = refreshListener; 
    } 

    @Override 
    public void onClick(View view) { 
     // TODO Auto-generated method stub 

     switch (view.getId()) { 
     case R.id.imgUrl_content: 
      sendDataItemContentActivity(); 
      break; 

     case R.id.contentHeader: 
      sendDataItemContentActivity(); 
      break; 

     case R.id.contentDesc: 
      sendDataItemContentActivity(); 
      break; 

     default: 
      break; 
     } 

    } 

    public void sendDataItemContentActivity() { 

     Intent intent = new Intent(mContext, ItemContent.class) 
       .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     intent.putExtra("contentTxt", utils.contentTxt); 
     intent.putExtra("contentHeader", utils.categoryHeader); 
     intent.putExtra("contentİmageUrl", utils.imageUrl); 
     intent.putExtra("contentCategoryName", utils.categoryName); 

     Bundle animBundle = ActivityOptions.makeCustomAnimation(mContext, 
       R.anim.anim, R.anim.anim2).toBundle(); 

     mContext.startActivity(intent, animBundle); 

    } 

} 
+1

StaggeredGridView是一個開源項目,那麼你爲什麼不看看源代碼來看看哪裏出了問題?如果確實存在錯誤,請添加問題或分叉項目,修復問題並提出合併請求。開源不僅是免費使用某人的代碼,而且也是關於貢獻。 – Egor

+0

對不起ı假設有人使用這個庫,並爭奪相同的問題。也可能是我的baseadapter或某個地方的錯誤。我只是想告訴我我錯在哪裏。並感謝您提供有關在github上開放問題的建議。 –

+0

@MustafaErturk你有關於這個問題的解決方案嗎? –

回答

0

我想我和你一起使用相同的pinterest樣式庫也有同樣的問題。我通過認沽解決我的問題,這

@Override 
public void onResume() { 
    // TODO Auto-generated method stub 
    super.onResume(); 
    mAdapter = new SearchSTGVAdapter(getActivity(), adsList, (Fragment)this);  
    ptrstgv.setAdapter(mAdapter); 

} 

以前我把它放在onCreate方法 爲了您的信息這,我實現一個視圖尋呼機這個Pinterest的風格不是一個滑動菜單