對不起2周的ArrayList組合成一個ArrayList和元素的混亂標題(沒有原因來解釋我的幾句話的問題)如何檢測listViewAdapter
這是我的情況:
我「M開發一個應用程序來收集郵票 我有JSON包含2 JSONArray爲"collectedStamp"
和"unCollectedStamp"
那些2 JSO NArrays存儲到 的ArrayLists分別"arraylistCollected"
和"arraylistUncollected"
並且還我有 的GridView向顯示累計和未收集的所有郵票
所以把那些 的ArrayList到ListViewAdapter
我不得不合並兩組"arraylistCollected"
和"arraylistUncollected"
到 ArrayList的命名"arraylistCombined"
現在所有的郵票顯示器在正確的GridView 1 BUT我想檢測的集郵和無人領取郵票使用戶知道巫郵票已經收集並沒有。 爲例使收集郵票多彩和未收集郵票黑與白,或者
我不知道如何檢測這些2個陣列"arraylistCollected"
和"arraylistUncollected"
的元素,以便以後我可以做什麼過任何的他們的形象。
您有什麼看法或想法來解決這個問題?
這JSON resul
{
"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;
}
}
好吧,我明白你在這裏做了但我應該在哪裏寫ListView中的if條件?我需要檢測收集和不收集這條線----- map.put(TAG_STAMP_IMAGE,jsonobject.getString(TAG_STAMP_IMAGE)); – ahmadssb
和內部ListViewAdapter用於處理標記圖像的代碼是從BUTTOM ---- imageLoader.DisplayImage(URL,ImageView的) – ahmadssb
4號線在基地適配器,您可以添加代碼 resultp.get(StampsActivity.TAG_TYPE) –