0

i want to get data from my table on myDB and i want to show the data to alertdialog, here's my code :

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

and i have a code like this :

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());

that's my code, Can somebody please show me a bit of code to CharSequence[] items = { ...... }; so i can get the data from myDB? please help me. Thanks

Richardo Luis
  • 37
  • 1
  • 2
  • 13

2 Answers2

0

Simply replace all occurrences of CharSequence in your code with String.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I want to show the data that already exists in my database into alert using charsequence, but I do not know how to call the data into alerts. Will you help me? – Richardo Luis Sep 12 '12 at 05:43
0

Convet from string array to charsequnce like this and get string you want 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()]);
Hitesh
  • 56
  • 1
  • 5