在我的应用程序中,我将联系人保存在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();
}
});
你不能在一个数组存储字符串无引用 –