我正在尝试将共享首选项打印到文本视图中,问题是当我尝试保存新的一个时,它会覆盖在previus上。 我需要帮助才能让他们成为一个不是压倒一切的时间。
public void loadPicture()
{
//this is how i load the sharedpreferences on another page.
gallery.removeAllViews();
List<String> array =fetchAllPreference();
for(int i=0;i<array.size();i++)
{
TextView iv = new TextView(this);
LinearLayout.LayoutParams layoutParams=new
LinearLayout.LayoutParams(200,200);
layoutParams.setMargins(10,10,0,0);
iv.setLayoutParams(layoutParams);
iv.setText(array.get(i));
gallery.addView(iv);
}
}
//how i save the sharedpreferences
sendnewword.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
SharedPreferences sharedPref =
getSharedPreferences("DictionaryInfo", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("Herbew", Hebrew.getText().toString());
editor.putString("English", English.getText().toString());
editor.apply();
Intent B = new Intent(New_words.this, All_words.class);
startActivity(B);
}
});
//making all sharedpreferences to an array.
public List<String> fetchAllPreference(){
SharedPreferences sharedPref = getSharedPreferences("DictionaryInfo",
Context.MODE_PRIVATE);
List<String> values = new ArrayList<String>();
int index = 0;
Map<String,?> allPrefs = sharedPref.getAll();
for(Map.Entry<String,?> entry : allPrefs.entrySet()){
values.add(entry.getValue().toString());
}
return values;
}
答案 0 :(得分:0)
首先创建JSONArray并在此数组中添加JSONObject。像
chflags nohidden /usr/local/share
享受