0

我使用https://github.com/bulletnoid/StaggeredGridView这个库来制作一个 pinterest 样式的布局,并在这个布局上使用 pulltorefresh。我也有一个幻灯片菜单,用于选择不同的类别,并根据用户选择的类别,刷新并重新填充交错。

Pulltorefresh 工作正常。

如果用户在布局顶部并在幻灯片菜单上选择一个类别,则它可以正常工作。但是,如果用户在布局底部并在幻灯片菜单上选择一个类别,则无法正常工作。

场景、布局顶部并在幻灯片菜单上选择类别并重新填充交错布局。它工作正常

布局顶部 在此处输入图像描述

场景、布局底部并在幻灯片菜单上选择类别并重新填充交错布局。它无法正常工作

布局底部 在此处输入图像描述

-->列表视图适配器

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

    }

}
4

1 回答 1

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 样式

于 2013-11-05T04:40:10.293 回答