ここで私は自分のコードを共有しています。どのようにリストビューでこのデータを解析できるのですか。最初はJson Parserを使用していますが、これは動作しません。今私はこれを解析してリストビューを見ることはできません。このおかげで私を助けてください。Android ListView Jsonでデータを解析する
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
public class HomeScreen extends Activity {
ListView listview;
String url;
ArrayList<ParticipantItem> participantArrayList;
ParticipantsAdapter pAdapter;
JSONArray jsonOuterArray;
private ProgressDialog pDialog;
ImageView menu, refresh;
Integer a;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home_screen);
participantArrayList = new ArrayList<ParticipantItem>();
listview = (ListView) findViewById(R.id.listview);
url = "http://findcourse.net/search_result.php?search=&study_field=17";//"http://findcourse.net/search_result.php?search=" + keywordvalue_get + sf_spinner_get + sl_spinner_get + si_spinner_get + sm_spinner_get;
refresh = (ImageView) findViewById(R.id.refresh);
menu = (ImageView) findViewById(R.id.menu);
new GetData().execute();
System.out.println("The square root of " + url);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
}
});
}
//////////////////////
private class GetData extends AsyncTask<String, String, String> {
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(HomeScreen.this);
pDialog.setMessage("Loading...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected void onPostExecute(String result) {
pDialog.dismiss();
if (jsonOuterArray.length() > 0) {
for (int i = 0; i <= jsonOuterArray.length(); i++) {
a = jsonOuterArray.length();
JSONObject jsonObj;
try {
jsonObj = jsonOuterArray.getJSONObject(i);
JSONObject message = jsonObj.getJSONObject("result");
String offered_by_detail = message.getString("offered_by");
String course = message.getString("course");
String logo = message.getString("logo");
String total_views = message.getString("total_views");
String total_course_offered = message.getString("total_course_offered");
String feature_course = message.getString("feature_course");
String total_views_course = message.getString("total_views_course");
String course_info = message.getString("course_info");
String duration = message.getString("duration");
String tution_fee = message.getString("tution_fee");
String other_payable_fee = message.getString("other_payable_fee");
String intake = message.getString("intakesandroid");
String campus = message.getString("campusandroid");
String entry_requirement = message.getString("entry_requirement");
String longitude = message.getString("longitude");
String latitude = message.getString("latitude");
String search_filter = message.getString("search_filter");
String institute_info = message.getString("institute_info");
// Toast.makeText(HomeScreen.this, institute_info, Toast.LENGTH_SHORT).show();
TextView search_filtera = (TextView) findViewById(R.id.search_filter);
// search_filtera.setText("Search for " + String.valueOf(a) + " institutions offering in Agriculture courses");
search_filtera.setText(search_filter);
participantArrayList.add(new ParticipantItem(offered_by_detail, logo, course, total_views, course_info, duration, tution_fee, other_payable_fee, intake, campus, entry_requirement, longitude, latitude, search_filter, institute_info, total_course_offered, feature_course, total_views_course));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
pDialog.dismiss();
}
}
} else {
}
pAdapter = new ParticipantsAdapter(getApplicationContext(), participantArrayList);
listview.setAdapter(pAdapter);
}
protected String doInBackground(final String... args) {
HttpHandler sh = new HttpHandler();
jsonOuterArray = new JSONArray();
String jsonOuterArray = sh.makeServiceCall(url);
return null;
}
}
}
あなたはapiを投稿できますか? – HaroldSer
http://findcourse.net/search_result.php?search=&study_field=17 – SAK
@SAKあなたのログを投稿すると、あなたはjsonの解析で間違っていると思います。 –