【发布时间】:2018-04-15 04:23:16
【问题描述】:
如何将共享首选项保存到数组中,我尝试了几件事,但我做不到,我想将特定键保存到数组中,然后将它们放入文本视图中,然后它就崩溃了. 请大家帮忙。
public String[] fetchAllPreference(){
SharedPreferences sharedPref = getSharedPreferences("DictionaryInfo",
Context.MODE_PRIVATE);
//here i want the code of making it into array come
return values;
}
public void loadPicture()
{
gallery.removeAllViews();
String[] array =fetchAllPreference();
for(int i=0;i<array.length;i++)
{
TextView iv = new TextView(this);
LinearLayout.LayoutParams layoutParams=new
LinearLayout.LayoutParams(100,100);
layoutParams.setMargins(10,10,0,0);
iv.setLayoutParams(layoutParams);
iv.setText(array[i].toString());
gallery.addView(iv);
}
}
【问题讨论】:
-
添加你的日志猫
-
显然每个
array[i],其中count(allPrefs) <= i < 1000等于null -
@Selvin 我没听懂你说什么
标签: android arrays sharedpreferences