下面是我的代码我使用两个json文件一个包含数据第二个包含日期问题仅在第二个json文件中我想首先检查json文件中是否存在日期,然后在textview中显示该日期的json数组“标题”在帖子 onPostExecute 中只需检查这一行 if (Vacation_Date.contains(mydate)) { 匹配然后在 onPostExecute 的 textview 中显示该日期的 json 数组“标题”怎么做???
static ArrayList<Long> Category_ID = new ArrayList<Long>();
static ArrayList<String> school_name = new ArrayList<String>();
static ArrayList<String> menu_name = new ArrayList<String>();
static ArrayList<String> dish_name = new ArrayList<String>();
static ArrayList<String> day = new ArrayList<String>();
static ArrayList<Long> Vacation_ID = new ArrayList<Long>();
static ArrayList<String> Vacation_name = new ArrayList<String>();
static ArrayList<String> Vacation_Date = new ArrayList<String>();
public class getDataTask extends AsyncTask<Void, Void, Void>{
getDataTask(){
if(!prgLoading.isShown()){
prgLoading.setVisibility(0);
txtAlert.setVisibility(8);
}
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
}
@Override
protected Void doInBackground(Void... arg0) {
// TODO Auto-generated method stub
parseJSONData();
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
prgLoading.setVisibility(8);
if((Category_ID.size() > 0) || IOConnect == 0){
listCategory.setAdapter(cla);
if (message.equals("weekly")) {
menu_nametxt.setText(mVal2);
listCategory.setVisibility(0);
} else if (message.equals("error")){
menu_nametxt
.setText("No menu available on this date! ");
listCategory.setVisibility(View.GONE);
}
else if (message.equals("holiday")){
menu_nametxt.setText(mVal2);
//menu_nametxt.setText(mVal2); not show title value on textview why????
listCategory.setVisibility(View.GONE);
}
}else{
txtAlert.setVisibility(0);
menu_nametxt.setText("");
listCategory.setVisibility(View.GONE);
}
}
}
public void parseJSONData() {
try {
String line;
String str = "";
while ((line = in.readLine()) != null) {
str += line;
}
JSONObject json3 = new JSONObject(str2);
status = json3.getString("status");
if (status.equals("1")) {
JSONArray school = json3.getJSONArray("data");
for (int k = 0; k < school.length(); k++) {
JSONObject jb = (JSONObject) school.getJSONObject(k);
Vacation_ID.add((long) k);
Vacation_Date.add(jb.getString("date"));
}
}
else {
}
JSONObject json2 = new JSONObject(str);
status = json2.getString("status");
if (status.equals("1")) {
if (Vacation_Date.contains(mydate)) {
message = "holiday";
JSONObject json4 = new JSONObject(str2);
status = json4.getString("status");
if (status.equals("1")) {
JSONArray school = json4.getJSONArray("data");
for (int k = 0; k < school.length(); k++) {
JSONObject jb = (JSONObject) school.getJSONObject(k);
Vacation_ID.add((long) k);
String[] mVal = new String[school.length()];
mVal[k] = school.getJSONObject(k).getString("title");
mVal2 = mVal[0];
}
}
{"status":1,
"data":
[
{"id":"1",
"title":"abc",
"date":"2013-09-29"},
{"id":"2",
"title":"abc1",
"date":"2013-09-25"},
{"id":"3",
"title":"abc",
"date":"2013-10-05"},
{"id":"4",
"title":"abc1",
"date":"2013-09-27"}]
}