Int from value of a String in android -


i have

string[] x1 = new string[] { "05:30", "07:20", "13:30", "21:30"}; string[] x2 = new string[] { "08:30", "01:20"};  string[] x3 = new string[] { "12:30", "00:20", "13:54"};  

from database receive x1 or x2 or x3 name.

string get_x = null; cursor cursor = db.rawquery(selectquery, null); if (cursor.movetofirst()) {     {         get_x = cursor.getstring(0); // get_x have value x1 or x2 or x3     } while (cursor.movetonext()); } 

and want size of returned x[1 or 2 or 3] eg. int size = x1.length, x1 value of get_x string.

i tried

int size = get_x.length;  

but not working. 'size' equal length of get_x, not length of x1.length

here answer using reflection :). pass get_x method. "yourclassname" - name of activity (or class hosting code), replace it.

            public void getsize(string arrayparamname){                 field[] fields = yourclassname.class.getdeclaredfields();                  (field field : fields) {                      //gives names of fields                     if(field.getname().equals(arrayparamname)) {                         system.out.println(field.getname());                         try {                              string[] returnedarrayfromdb = (string[])field.get(cameraactivity.this);                             system.out.println("length of " +field.getname() + ":  "+ returnedarrayfromdb.length);                             system.out.println("first value of array " +returnedarrayfromdb[0]);                           } catch (illegalaccessexception e) {                             e.printstacktrace();                         }                     }                 }             } 

Comments