紛らわしいタイトルで申し訳ありません(私の問題を短い言葉で説明する理由はありません)
これは私の状況です:
私は2つのJSONArrayを含むJSONを持っているスタンプを収集 するアプリを開発しています "collectedStamp"
"unCollectedStamp"
"arraylistCollected"
"arraylistUncollected"
また、収集済みおよび未収集のすべてのスタンプを表示するためのGridViewが1 つあります。
そのため、これらの2 つの ArrayListを配置するListViewAdapter
には、両方を組み合わせて"arraylistCollected"
、名前付きの1つの Arraylist"arraylistUncollected"
にする必要がありました"arraylistCombined"
すべてのスタンプが 1 つの GridView で正しく表示されるようになりましたが、収集されたスタンプと収集されていないスタンプを検出して、魔女のスタンプが収集されたかどうかをユーザーが認識できるようにしたいと考えています。たとえば、集めたスタンプをカラフルに、未収集のスタンプを黒と白に、または
"arraylistCollected"
これら2つの配列の要素を検出する方法がわからない"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;
}
}