0

我想从 myDB 上的表中获取数据,并且想将数据显示到 alertdialog,这是我的代码:

public void gotResult(String result, String message) {
        // TODO Auto-generated method stub
        if (result != null) {
            switch (Action) {
            case VIEW_BIKE_TYPE:
                try {
                    JSONObject jsonObject = null;
                    jsonObject = new JSONObject(result);
                    int response = jsonObject.getInt("result");
                    if (response != 0) {
                        JSONArray jsonArray = new JSONArray(
                                jsonObject.getString("data"));


                        CharSequence[] items = new CharSequence[jsonArray.length()];

                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject biketype = new JSONObject(jsonArray
                                    .get(i).toString());


                            items[i] = biketype.getString("type_name");
                        }
                        bike_type_Result.gotResult(items, null, Action);
                    } else {
                        String error_message = jsonObject
                                .getString("message");
                        bike_type_Result.gotResult(null, error_message,
                                Action);
                    }
                } catch (JSONException e) {
                    // TODO: handle exception
                    bike_type_Result.gotResult(null,
                            "Failed parsing data from database. Please try again.. "
                                    + e.getMessage(), Action);
                    Log.e("CON ERROR", e.getMessage());
                }
            }
        } else {
            bike_type_Result.gotResult(null, message, Action);
            Log.e("CON ERROR", message);
        }
    }
};

我有这样的代码:

protected void onListItemClick(ListView l, View v, int position, long id) {

    final Entity_Brand brand = adapterBrand.getItem(position);

    CharSequence[] items = { ...... };

    AlertDialog.Builder builder = new AlertDialog.Builder(
            Tab_Brand_ListView_Activity.this);
    builder.setIcon(R.drawable.alert_brand_logo);
    builder.setTitle(brand.getBrand_name());

那是我的代码,有人可以给我看一些代码,CharSequence[] items = { ...... };以便我可以从 myDB 获取数据吗?请帮我。谢谢

4

2 回答 2

0

像这样从字符串数组转换为字符序列并获取您想要的字符串 List listItems = new ArrayList();

    listItems.add("Take Photo");
    listItems.add("Choose From Gallery");
    if (flagImage == 1) {
        listItems.add("Remove Photo");

    }
    listItems.add("Cancel");

    final CharSequence[] items = listItems.toArray(new CharSequence[listItems.size()]);
于 2014-06-23T13:42:14.330 回答
0

只需将CharSequence代码中出现的所有 . 替换为String.

于 2012-09-09T16:01:25.477 回答