JSONデータがSimpleAdapterに取り込まれるlistViewを作成しようとしていますが、nullが返された場合にランク画像を非表示にする方法を理解できます。
private class LoadDataTask extends AsyncTask<Void, Void, String[]> {
ProgressDialog Dialog = new ProgressDialog(Post.this);
@Override
protected void onPreExecute() {
super.onPreExecute();
mylist.clear();
Dialog.setMessage("Loading Posts...");
Dialog.setCancelable(true);
Dialog.show();
}
@Override
protected String[] doInBackground(Void... params) {
preferences = PreferenceManager.getDefaultSharedPreferences(Post.this);
String userID = preferences.getString("userID", "n/a");
String TID = Post.this.getIntent().getExtras().getString("id");
try{
JSONObject json = JSONfunctions.getJSONfromURL(Constants.BASE_URL+"/posts.php?user="+userID+"&postID="+TID);
JSONArray users = json.getJSONArray("users");
for(int i=0;i<users.length();i++){
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = earthquakes.getJSONObject(i);
map.put("pid", e.getString("poster_id"));
map.put("id", e.getString("post_id"));
map.put("Forum", e.getString("forum_id"));
map.put("Topic", e.getString("topic_id"));
map.put("Name", e.getString("poster_name"));
map.put("Text", string);
map.put("IP", e.getString("poster_ip"));
map.put("Status", e.getString("poster_status"));
map.put("Rank", e.getString("prank"));
map.put("Time", e.getString("poster_time"));
map.put("active", e.getString("active"));
map.put("posterisimage", e.getString("posterisimage"));
map.put("posterimage", e.getString("posterimage"));
mylist.add(map);
}
}catch(JSONException e) {
Log.e("log_tag", "Error parsing data "+e.toString());
}
return null;
}
@Override
protected void onPostExecute(String[] result) {
ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.main,
new String[] { "Time", "Text", "Name" ,"Rank"}, <==Hide Rank if returned null ???
new int[] { R.id.item_date, R.id.item_subtitle , R.id.item_title, R.id.item_image});
((SimpleAdapter) adapter).notifyDataSetChanged();
setListAdapter(adapter);
Dialog.dismiss();
super.onPostExecute(result);
}
}
誰かが私に正しい方向を示したり指さしたりできますか.