I think im going about this all wrong and just need a push in the right direction. I parsed my json information and set them to set fields, so each one can be called and displayed. Now this only works for 1 field at a time I can't load more than one using the adapter. Do I need to compile all of these arrays into one to be called via a custom adapter? Here is my code:
public class LocalJsonFileActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
BufferedReader jsonReader = new BufferedReader(new InputStreamReader(this.getResources().openRawResource(R.raw.localjsonfile)));
StringBuilder jsonBuilder = new StringBuilder();
for (String line = null; (line = jsonReader.readLine()) != null;) {
jsonBuilder.append(line).append("\n");
}
JSONTokener tokener = new JSONTokener(jsonBuilder.toString());
JSONArray jsonArray = new JSONArray(tokener);
ArrayList<String> name = new ArrayList<String>();
for (int index = 0; index < jsonArray.length(); index++) {
JSONObject jsonObject = jsonArray.getJSONObject(index);
name.add(jsonObject.getString("name"));
}
ArrayList<String> bloodtype = new ArrayList<String>();
for (int index = 0; index < jsonArray.length(); index++) {
JSONObject jsonObject = jsonArray.getJSONObject(index);
bloodtype.add(jsonObject.getString("bloodtype"));
}
ArrayList<String> type = new ArrayList<String>();
for (int index = 0; index < jsonArray.length(); index++) {
JSONObject jsonObject = jsonArray.getJSONObject(index);
type.add(jsonObject.getString("type"));
}
ArrayList<String> dob = new ArrayList<String>();
for (int index = 0; index < jsonArray.length(); index++) {
JSONObject jsonObject = jsonArray.getJSONObject(index);
String series = jsonObject.getString("dob");
if (series.equals("December")) {
dob.add(jsonObject.getString("dob"));
}
}
setListAdapter(new ArrayAdapter<String>
(this, R.layout.usercard, R.id.txttype, type));
} catch (FileNotFoundException e) {
Log.e("jsonFile", "file not found");
} catch (IOException e) {
Log.e("jsonFile", "ioerror");
} catch (JSONException e) {
Log.e("jsonFile", "error while parsing json");
}
}
}
layout main is just a blank list view. My layout card has 4 fields 1 that is image view. But I can't seem to show more than 1 piece of information. Reading data in single fields and then outputting is great. I would just like to add the text to all fields.