0

抱歉标题令人困惑(没有理由用几句话来解释我的问题)

这是我的情况:

我正在开发一个应用程序来收集邮票我有包含 2 个 JSONArray的JSON,"collectedStamp"并且这 2 个 JSONArrays分别 "unCollectedStamp"存储到2 个 ArrayLists"arraylistCollected"中,"arraylistUncollected"

而且我有1 个 GridView来显示所有收集未收集的邮票

所以要将这2 个 ArrayList放入ListViewAdapter 我必须将两者合并"arraylistCollected""arraylistUncollected"1名为"arraylistCombined"

现在所有邮票在 1 个 GridView 中正确显示,但我想检测收集的邮票和未收集的邮票,以便用户知道女巫邮票已被收集,哪些未收集。例如,将收集的邮票制作成彩色和未收集的邮票黑白,或者

我不知道如何检测这两个数组的元素,"arraylistCollected"所以"arraylistUncollected" 以后我可以对他们的任何图像做任何事情。

您对解决这个问题有什么意见或想法?

这个 JSON 结果

{
    "status": "1",
    "tappedStamp": "15",
    "message": "stamp message",
    "stampimage": "stamp3.png",
    "stampname": "stamp3",
    "collectedStamp": [
        {
            "id": "14",
            "stampname": "stamp2 ",
            "message": "stamp2 message",
            "stampimage": "stamp2.png"
        },
        {
            "id": "15",
            "stampname": "stamp3",
            "message": "stamp message",
            "stampimage": "stamp3.png"
        }
    ],
    "unCollectedStamp": [
        {
            "id": "12",
            "stampname": "Testing MKH Stamp",
            "message": "Testing MKH Stamp",
            "stampimage": "award.png"
        },
        {
            "id": "13",
            "stampname": "stamp1",
            "message": "stamp1 Message",
            "stampimage": "stamp1.png"
        },
        {
            "id": "16",
            "stampname": "Testing MKH Stamp",
            "message": "Testing MKH Stamp",
            "stampimage": "award.png"
        }
    ]
}

这是下载 JSON 的代码

        @Override
        protected Void doInBackground(Void... params) {
            // Create an array
            arraylistCollected = new ArrayList<HashMap<String, String>>();
            arraylistUncollected = new ArrayList<HashMap<String, String>>();



            this.sharedPref = getSharedPreferences(getString(R.string.key_storage),0);
            this.eventID = sharedPref.getString("eventid", null);
            this.kioskid = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
            this.tagid = sharedPref.getString("tagID", null);
            this.accesstoken = sharedPref.getString("accesstoken", null);


            try {
                // building parameters for Logout
                List<NameValuePair> param = new ArrayList<NameValuePair>();
                param.add(new BasicNameValuePair(TAG_ACCESSTOKEN, accesstoken));
                param.add(new BasicNameValuePair(TAG_KIOSK_ID, kioskid));
                Log.d("request!", "Starting");


            // Retrieve JSON Objects from the given URL address
            jsonobject = JSONParser.makeHttpRequest(STAMPS_LIST_URL,"POST",param);
            Log.d("Loding Stamps Attemp", jsonobject.toString());

            // get tapped Stamp Image Url 
            tappedStampImageUrl = jsonobject.getString(TAG_STAMP_IMAGE);

            // Locate UNCOLLECTED STAMPS array name in JSON
            jsonArrayUncollected = jsonobject.getJSONArray(TAG_UNCOLLECTED_STAMPS);

            for (int i = 0; i < jsonArrayUncollected.length(); i++) {
                HashMap<String, String> map = new HashMap<String, String>();
                JSONObject jsonobject = jsonArrayUncollected.getJSONObject(i);

                // Retrive JSON Objects
                map.put(TAG_STAMPS_ID, jsonobject.getString(TAG_STAMPS_ID));
                map.put(TAG_STAMP_IMAGE, jsonobject.getString(TAG_STAMP_IMAGE));
                map.put(TAG_STAMP_NAME, jsonobject.getString(TAG_STAMP_NAME));
                map.put(TAG_MESSAGE, jsonobject.getString(TAG_MESSAGE));
                // Set the JSON Objects into the array
                arraylistUncollected.add(map);
            }
Log.d("jsonArrayUncollected Size:", ""+arraylistUncollected.size());


            // Locate COLLECTED STAMPS array name in JSON
            jsonArrayCollected = jsonobject.getJSONArray(TAG_COLLECTED_STAMPS);

            for (int i = 0; i < jsonArrayCollected.length(); i++) {
                HashMap<String, String> map = new HashMap<String, String>();
                JSONObject jsonobject = jsonArrayCollected.getJSONObject(i);

                // Retrive JSON Objects
                map.put(TAG_STAMPS_ID, jsonobject.getString(TAG_STAMPS_ID));
                map.put(TAG_STAMP_IMAGE, jsonobject.getString(TAG_STAMP_IMAGE));
                map.put(TAG_STAMP_NAME, jsonobject.getString(TAG_STAMP_NAME));
                map.put(TAG_MESSAGE, jsonobject.getString(TAG_MESSAGE));

                // Set the JSON Objects into the array
                arraylistCollected.add(map);
            }
            Log.d("jsonArrayCollected Size:", ""+arraylistCollected.size());


                arraylistCombined = new ArrayList<HashMap<String, String>>();
                arraylistCombined.addAll(arraylistCollected);
                arraylistCombined.addAll(arraylistUncollected);

                Log.d("arraylistCombined Size:", ""+arraylistCombined.size());


            } catch (JSONException e) {
                Log.e("Error", e.getMessage());
                e.printStackTrace();
            }
            return null;
        }

    @Override
            protected void onPostExecute(Void args) {

                imageLoader.DisplayImage(TAG_IMAGE_URL+tappedStampImageUrl, tappedStampImage);
                Animation myFadeInAnimation = AnimationUtils.loadAnimation(StampsActivity.this, R.anim.fadein);
                tappedStampImage.startAnimation(myFadeInAnimation);
                // Locate the listview in listview_main.xml
                //listview = (ListView) findViewById(R.id.listview);
                gridView = (GridView) findViewById(R.id.gridView1);

                // Pass the results into ListViewAdapter.java
                adapter = new ListViewAdapter(StampsActivity.this, arraylistCombined);

                // Set the adapter to the ListView
                //listview.setAdapter(adapter);
                gridView.setAdapter(adapter);
                // Close the progressdialog
                mProgressDialog.dismiss();
            }
        }

这是 ListViewAdapter

public class ListViewAdapter extends BaseAdapter {

    // Declare Variables
    Context context;
    LayoutInflater inflater;
    ArrayList<HashMap<String, String>> data;
    ImageLoader imageLoader;
    HashMap<String, String> resultp = new HashMap<String, String>();

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

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

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

    public View getView(final int position, View convertView, ViewGroup parent) {
        // Declare Variables

        TextView tvStampName;
        ImageView stampImage;

        inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View itemView = inflater.inflate(R.layout.single_stamp_layout, parent, false);
        // Get the position
        resultp = data.get(position);

        tvStampName = (TextView) itemView.findViewById(R.id.tvStampName);
        stampImage = (ImageView) itemView.findViewById(R.id.stampImage);

        tvStampName.setText(resultp.get(StampsActivity.TAG_STAMP_NAME));

        // Passes stampImage images URL into ImageLoader.class
        imageLoader.DisplayImage(TAG_STAMP_IMAGE_URL+resultp.get(StampsActivity.TAG_STAMP_IMAGE), stampImage);
        Animation myFadeInAnimation = AnimationUtils.loadAnimation(context, R.anim.fadein);
        stampImage.startAnimation(myFadeInAnimation);
        return itemView;
    }
}
4

1 回答 1

0

在将值放入哈希映射时,以这种方式再添加一个值:

map.put(TAG_TYPE, "COLLECTED");

对于未收集:

map.put(TAG_TYPE, "UNCOLLECTED");

那么您可以轻松区分它

于 2014-04-15T07:55:55.497 回答