Android在没有XML的情况下更改字符串的颜色

时间:2013-12-02 15:25:07

标签: java android xml

我想从json对象更改字符串“title”的颜色,并将其放在带有不带XML的数组适配器的listview中。

我已经尝试了很多stackoverflow的例子,但我不确定,如果我使用的数组适配器是正确的。

当我测试这些例子时,我总是成为同样的例外:

RuntimeException:无法启动活动ComponentInfo

有什么建议吗?

谢谢!

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;
}

}

1 个答案:

答案 0 :(得分:0)

您是否已将活动添加到清单文件中?