在我的應用程序中,我將聯繫人保存在SharedPreferences中,但我傳遞的數組還包括字符串中的開放大括號和雙引號。從數組中移除大括號和雙引號
這樣[ 「contactnumber1」, 「contactnumber2」, 「contactnumber3」 .......]
但我需要字符串是這樣 contactnumber1,contactnumber2,contactnumber3 ....
這樣我就可以使用這個contactnumbers字符串直接將其放入短信應用程序並通過單擊按鈕發送警報消息。
請幫我這個
代碼:
String[] arrayOfString=localMultiAutoCompleteTextview.getText().toString().split(",");
// Create a JSONArray to store all numbers
JSONArray numberArray=new JSONArray();
// Loop through the multiautocomplete textview value array
for(int i=0; i < arrayOfString.length; i++)
{
// Check whether the string contains '%'
if(arrayOfString[i].contains("%"))
{
// Add numbers to the array
numberArray.put(arrayOfString[i].split("%")[1]);
}
}
// Store the complete number array in preference as String
sp=getActivity().getSharedPreferences("sdat", 2);
ed=sp.edit();
ed.putString("snum", numberArray.toString());
ed.commit();
// To read the numbers after saving
String display = sp.getString("snum", new JSONArray().toString());
System.out.println(display);
Toast.makeText(getActivity(),"Contacts Saved:"+display,Toast.LENGTH_SHORT).show();
}
});
你不能在一個數組存儲字符串無引用 –