1

I want to put data from a MySQL database table into Android Studio.
For modifying script from tutorial.

In tutorial ArrayList value is:

HomeCollection.date_collection_arr = new ArrayList<HomeCollection>();
HomeCollection.date_collection_arr.add(new HomeCollection("2018-07-08" ,"Title1","Subject1","Description1"));
HomeCollection.date_collection_arr.add(new HomeCollection("2018-07-09" ,"Title2","Subject2","Description2"));
HomeCollection.date_collection_arr.add(new HomeCollection("2018-07-10" ,"Title3","Subject3","Description3"));

My Question:

How to modify data Array, in example with all data in MySql table having below columns?

| id | date | title | subject | description |

Any help will be greatly appreciated

1
  • First of All what's your database SQLite or MySQL? Commented Jul 5, 2018 at 9:06

2 Answers 2

1

//you can do like this. get the value from arraylist into string array then split the array and then send the string to database.given below code

 String[] value = HomeCollection.date_collection_arr.get(0).split(",");
 String date=value[0];
 String title=value[1];
 String description=value[2];

//if your array list value contain space use below code

 String[] valuetrim= HomeCollection.date_collection_arr.get(0).split("\\s*,\\s*");
 String valuetrim=value[0];
 String valuetrim=value[1];
 String valuetrim=value[2];
Sign up to request clarification or add additional context in comments.

Comments

0

Thanx for your clue, but I still not understand,

I try to get array list, from this way n success to views data at list (bellow array scrip),

maybe someone can give me more specific, how to implement/combine value data i have got from this way (below) to array at my question (i want to impemented sample script from this link https://www.developerbrothers.com/highlight-events-custom-calendar-android-studio-developerbrothers-com/) but i want data values get from MySql, Thanks

private void showOrder(){ JSONObject jsonObject = null; ArrayList> list = new ArrayList>(); try { jsonObject = new JSONObject(JSON_STRING); JSONArray result = jsonObject.getJSONArray(konfigurasi.TAG_JSON_ARRAY);

        for(int i = 0; i<result.length(); i++){
            JSONObject jo = result.getJSONObject(i);

            String idplace = jo.getString(konfigurasi.TAG_PLACE);
            String titl = jo.getString(konfigurasi.TAG_TITLE);
            String subj = jo.getString(konfigurasi.TAG_SUBJECT);
            String desc= jo.getString(konfigurasi.TAG_DESCRIPTION);
            String dateo = jo.getString(konfigurasi.TAG_DATEORDER);

            HashMap<String,String> orders = new HashMap<>();

            orders.put(konfigurasi.TAG_PLACE,idplace);
            orders.put(konfigurasi.TAG_TITLE,titl);
            orders.put(konfigurasi.TAG_SUBJECT,subj);
            orders.put(konfigurasi.TAG_DESCRIPTION,desc);

            orders.put(konfigurasi.TAG_DATEORDER,dateo);
            list.add(orders);
        }

    } catch (JSONException e) {
        e.printStackTrace();
    }

    ListAdapter adapter = new SimpleAdapter(
            DateEventActivity.this, list, R.layout.list_item,
            new String[]{konfigurasi.TAG_PLACE,konfigurasi.TAG_TITLE,konfigurasi.TAG_SUBJECT,konfigurasi.TAG_DESCRIPTION,konfigurasi.TAG_DATEORDER},
            new int[]{R.id.idplace, R.id.titl, R.id.subj, R.id.desc, R.id.dateo});

    listView.setAdapter(adapter);
}

private void getJSON(){
    class GetJSON extends AsyncTask<Void,Void,String> {

        ProgressDialog loading;
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            loading = ProgressDialog.show(DateEventActivity.this,"Mengambil Data","Mohon Tunggu...",false,false);
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            loading.dismiss();
            JSON_STRING = s;
            showOrder();
        }

        @Override
        protected String doInBackground(Void... params) {
            RequestHandler rh = new RequestHandler();
            String s = rh.sendGetRequest(konfigurasi.URL_GET_ALL);
            return s;
        }
    }
    GetJSON gj = new GetJSON();
    gj.execute();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.