Skip to main content

Posts

Showing posts from November, 2017

How to create a Json Object from group of String in java (Android)

                             Create  Json object from strings in java String string ; JSONObject obj = new JSONObject() ; json.put( "name" , "Ram" ) ; JSONArray myarr = new JSONArray() ; JSONObject json = new JSONObject() ; json.put( "address" , "test" ) ; json.put( "id" , 3 ) ; json.put("course " , "MCA" ) ; array.put(json) ; json.put( "0" , arr) ; string = json.toString() ; Output: // string // {"0":[{"id":3,"address":"test","course":"MCA"}],"name":"Ram"}

Split a String in java at particular character

                     Split string to make a subString in java or (Android)  1. String replace function String str = "Hello^how are you" ; String newStr = str . replaceAll ( "[^]+" , "1" ); 2. To split a String in java  at particular character Write these lines of code which are given below String str = "hello, goachivers" ; String[] output = str .split( "," ) ; String str1 = output[ 0 ] ; String str2=output[ 1 ] ; To print the vale of str1 and str2 For java: System.out.println( output[ 0 ]); System.out.println( output[ 1 ]); For Android Toast. makeText(getApplicationContext() ,"str1:"+str1 , Toast . LENGTH_SHORT ).show() ; Toast. makeText(getApplicationContext() ,"str2:"+str2 , Toast . LENGTH_SHORT ).show() ; Output : str1:hello str2:goachivers

EditText Not working in Custom ListView in Android

OnClick EditText Looses Focuse in Custom ListView In Android If you set up your layout like the one showed above you'll soon have to deal with an annoying problem. For some unknown reason the EditText immediately loses focus, and it's almost impossible to write anything. Fortunately the solution is quite easy: you just have to add the following lines of code: in the AndroidManifest.xml file add the following line for the Activity containing the ListView: android:windowSoftInputMode="adjustPan"; in the layout file of the Activity add the following line to your ListView: 1. android:windowSoftInputMode= "stateHidden|adjustPan" 2. android:descendantFocusability="beforeDescendants" <activity android :name= ".TestReading" android :windowSoftInputMode= "stateHidden|adjustPan" /> </application>   <ListView android :id= "@+id/light_list"