lundi 4 janvier 2016

Get data from database and use in interface in android

I am using Urls class(code given below) to set different urls I want to use in my app

    public interface Urls {
        public String SERVER_BASE_URL = "http://webaddress.com/";
    public String URL_DIRECT =SERVER_BASE_URL + "token.php";
        public String URL_DIRECT2= SERVER_BASE_URL + "token2.php";
        public String URL_DIRECT3= SERVER_BASE_URL + "token3.php";
    }

Now I want to change the value of SERVER_BASE_URL from static value to a value from my database. The IP address is correctly stored in the database. For this I use the basic code as I need this page appear only once to store the IP address.

mydatabase = openOrCreateDatabase("IP", MODE_PRIVATE, null);
mydatabase.execSQL("CREATE TABLE IF NOT EXISTS value1(ipaddress VARCHAR);");
String a = ip.getText().toString();
mydatabase.execSQL("INSERT INTO value1 VALUES('" + a + "');");

I am getting the correct IP from database using this code

Cursor resultSet = mydatabase.rawQuery("Select * from value1", null);
                resultSet.moveToFirst();
                address = resultSet.getString(0);

But I don't know how to set this IP to the SERVER_BASE_URL programmatically. Or I want to get value from database on each activity ??? Please help!!!!

Aucun commentaire:

Enregistrer un commentaire