I would like to change the color of the string "title" from a json object and put it in a listview with an array adapter without XML.
I have tried a lot of examples of stackoverflow, but I am not sure, if the array adapter, which I am using, is the right one.
When I was testing the examples I always became the same exception:
RuntimeException: Unable to start activity ComponentInfo
Any suggestions?
Thank you!
public class TermineDetail extends ListActivity {
static JSONArray jArray;
static JSONObject jObject;
ArrayAdapter<String> adapter;
static int clickedPosition;
static String title;
public void getJsonArrayAndClickedPosition(JSONArray array, int position) {
this.jArray = array;
this.clickedPosition = position;
System.out.println("clickedPosition " + clickedPosition);
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adapter = new ArrayAdapter<String>(this.getBaseContext(),
R.layout.listview_simple_layout, this.getJsonResource());
}
public ArrayList<String> getJsonResource() {
ArrayList<String> listItems = new ArrayList<String>();
try {
for (int i = 0; i < jArray.length(); i++) {
if (i == clickedPosition) {
jObject = jArray.getJSONObject(i);
title = (String) jObject.get("title");
TextView tv = (TextView) findViewById(R.id.text_simple_listview);
tv.setText(Html.fromHtml("Your big island <b>ADVENTURE!</b>"));
listItems.add("\n" + "\n" + jObject.getString("title")
+ "\n" + "\n" + "\n" + "Datum: "
+ jObject.getString("termin") + "\n" + "\n"
+ "Uhrzeit: " + jObject.getString("time") + "\n"
+ "\n" + "Beschreibung: "
+ jObject.getString("text") + "\n" + "\n"
+ "Location: " + jObject.getString("location")
+ "\n" + "\n" + "Kontaktperson: "
+ jObject.getString("contactperson") + "\n" + "\n"
+ "Kontaktdaten: "
+ jObject.getString("contactdata") + "\n" + "\n");
setListAdapter(adapter);
}
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return listItems;
}
}