StaggeredGridView无法清除

时间:2014-07-23 16:31:00

标签: php android mysql json android-gridview

我正在使用Android StaggeredGridView库,我试图使用JSON php和mysql填充GridView。我需要解释一下,为什么StaggeredGridView搜索后无法清除?因为我创建了搜索功能。提前谢谢。

gridView.removeAllViews(); // not working
adapter.clear(); // not working too

我的适配器

public class CharStagAdapter extends BaseAdapter {

    Context context;
    ArrayList<HashMap<String, String>> urlimagelist;
    ImageLoader imageLoader;
    HashMap<String, String> map = new HashMap<String, String>();

    public CharStagAdapter(Context context,
            ArrayList<HashMap<String, String>> arraylist) {
        this.context = context;
        urlimagelist = arraylist;
        imageLoader = new ImageLoader(context);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return urlimagelist.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        ScaleImageView imageView;
        TextView tvProfileName, tvNickName;
        //tvDescription;

        if (convertView == null) {
            LayoutInflater layoutInflator = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            convertView = layoutInflator.inflate(R.layout.show_staggered, null);
        }

        map = urlimagelist.get(position);

            tvProfileName = (TextView) convertView.findViewById(R.id.tvProfileName);
            tvNickName = (TextView) convertView.findViewById(R.id.tvNickName);

            tvProfileName.setText(map.get(FragmentShowChar.PROFILE_NAME));
            tvNickName.setText(map.get(FragmentShowChar.NICKNAME));

            imageView = (ScaleImageView) convertView.findViewById(R.id.ivGridImage);
            imageLoader.DisplayImage(map.get(FragmentShowChar.URL), imageView);

        return convertView;
    }
}

Class Fragment

class SearchGridImageURL extends AsyncTask<String, String, String> {

        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();
            pDialog = new ProgressDialog(getActivity());
            pDialog.setMessage("Loading....");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }

        @Override
        protected String doInBackground(String... args) {
            // TODO Auto-generated method stub

            //String getSearch = edSearch.getText().toString();
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("profile_name", "Dya Sandra"));
            JSONObject json = jPostget.makeHttpRequest(url_search_image, "GET", params);
            Log.d("All GridView Image: ", json.toString());
            try {
                int success = json.getInt(KEY_SUCCESS);
                if (success == 1) {
                    members = json.getJSONArray(KEY_MEMBERS);
                    for (int i = 0; i < members.length(); i++) {
                        JSONObject c = members.getJSONObject(i);

                        String imageurl = c.getString(KEY_URL);
                        String sname = c.getString(KEY_PROFILE_NAME);
                        String snickname = c.getString(KEY_NICK_NAME);

                        HashMap<String, String> map = new HashMap<String, String>();

                        map.put(KEY_URL, imageurl);
                        map.put(KEY_PROFILE_NAME, sname);
                        map.put(KEY_NICK_NAME, snickname);

                        urlimagelist.add(map);
                    }
                } else {
                    // done
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(String file_url) {
            // TODO Auto-generated method stub
            pDialog.dismiss();
            getActivity().runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    // TODO Auto-generated method stub
                    gridView = (StaggeredGridView) getView().findViewById(R.id.staggeredGridView1);
                    adapter = new CharStagAdapter(getActivity(), urlimagelist);
                    gridView.setAdapter(adapter);
                    adapter.notifyDataSetChanged();
                }
            });
        }
    }

0 个答案:

没有答案