0

i have a problem with format arrayList.I have one parameter it have value

Licence_car:[[คย1453 กรุงเทพมหานคร], [รง2344 กรุงเทพมหานคร], [รน4679 กรุงเทพมหานคร]] (Data is a ThaiLanguage)

I use this parameter to set entry of list preference but it will show like this enter image description here

I want to delete character is "[" and "]" to make a variable like this Licence_car:[คย1453 กรุงเทพมหานคร, รง2344 กรุงเทพมหานคร, รน4679 กรุงเทพมหานคร] how can i do that?

This is my code set entry to list preference.

@SuppressWarnings("unchecked")
public void showCar(Context context,ArrayList<String> currentCars){
    SharedPreferences MYprefs = context.getSharedPreferences(PREFERENCES, PREFERENCE_MODE);

    if (null == currentCars) {
            currentCars = new ArrayList<String>();
        }
        try {
            currentCars = (ArrayList<String>) ObjectSerializer.deserialize(MYprefs.getString("car_licence_", ObjectSerializer.serialize(new ArrayList<String>())));
            //String[] car_list = currentCars.toCharArray;
            Log.d(TAG,"Licence_car:"+currentCars);  
            final CharSequence[] charSequenceCarEntry = currentCars.toArray(new CharSequence[currentCars.size()]);                    

            mCarDefault.setEntries(charSequenceCarEntry);
            mCarDefault.setEntryValues(charSequenceCarEntry); 
            mCarDelete.setEntries(charSequenceCarEntry);
            mCarDelete.setEntryValues(charSequenceCarEntry);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
}

I get a preference value in arrayList and format to CharSequence[] for set entry to list preference i think that i do format from this point but i don't know how can do it.

Thank for any answer and sorry for my English.

King_Dark
  • 299
  • 1
  • 4
  • 14
  • just before getting currentCars, can u add `Log.d(TAG,MYprefs.getString("car_licence_",""));` and post the result here – Nizam Aug 28 '13 at 04:20
  • yes i do your log request but result log is '08-28 11:24:53.446: D/DebugLog(8251): kmonaaafhdhcaabdgkgbhggbcohfhegjgmcoebhchcgbhjemgjhdhehiibncbnjjmhgbjnadaaabejaaaehdgjhkgfhihaaaaaaaadhhaeaaaaaaamheaadefloaliieoalikcdbdedfddcaoaliiboalikdoalilioaliihoaljiaoalijhoalijooalikboalikloalilcoalijjoaliieoalikdfnheaadefloalikdoaliihdcdddedecaoaliiboalikdoalilioaliihoaljiaoalijhoalijooalikboalikloalilcoalijjoaliieoalikdfnheaadefloalikdoalijjdedgdhdjcaoaliiboalikdoalilioaliihoaljiaoalijhoalijooalikboalikloalilcoalijjoaliieoalikdfnhi' – King_Dark Aug 28 '13 at 04:26
  • i don't know why log is show this text also this is a Ancient text? haha (joke :D) – King_Dark Aug 28 '13 at 04:28
  • hi hi ;) I asked to log it to know what is in preference string. But computer speaks ancient as you said :D. Don't know why. May be English representation of Thai. – Nizam Aug 28 '13 at 04:38
  • i think same your idea is "May be English representation of Thai" – King_Dark Aug 28 '13 at 04:45

2 Answers2

0

Hello Developer, You can foramt your charsequence before storing into array list ,hete i am giving the sample code please use it so here it is-

CharSequence[] charSequenceCarEntry = new CharSequence[10];         
        int startindex=charSequenceCarEntry.toString().indexOf("[");
        int endindex=charSequenceCarEntry.toString().indexOf("]");
        CharSequence cs =charSequenceCarEntry.toString().substring(startindex, endindex);

so in your case use it like-

currentCars = (ArrayList<String>) ObjectSerializer.deserialize(MYprefs.getString("car_licence_", ObjectSerializer.serialize(new ArrayList<String>())));
final CharSequence[] charSequenceCarEntry = currentCars.toArray(new CharSequence[currentCars.size()]);                    
int startindex=charSequenceCarEntry.toString().indexOf("[");
int endindex=charSequenceCarEntry.toString().indexOf("]");
CharSequence cs =charSequenceCarEntry.toString().substring(startindex, endindex);
mCarDefault.setEntries(cs);
mCarDefault.setEntryValues(cs); 
mCarDelete.setEntries(cs);
mCarDelete.setEntryValues(cs);
Ravi
  • 2,277
  • 3
  • 22
  • 37
  • Yeah it sound so good but it not work because i have got a error something with startindex is value-1 and endindex is value 0 but not problem i have solve my problem in next answer.Thank for your answer:D – King_Dark Aug 28 '13 at 06:10
0

I have solve this problem. I create input variable is type list<string> car_entry; to input a car_licence and output result is [คย1453 กรุงเทพมหานคร] so i will try to change type variable to String and the output is คย1453 กรุงเทพมหานคร as a result of charSequenceCarEntry is Licence_car:[คย1453 กรุงเทพมหานคร, รง2344 กรุงเทพมหานคร, รน4679 กรุงเทพมหานคร].Ok now It is done thank for any answer again. :)

King_Dark
  • 299
  • 1
  • 4
  • 14