小编Alg*_*tis的帖子

将数组保存到共享首选项并在列表视图中显示它

我需要将用户输入保存到共享首选项,并从列表视图中的共享首选项中显示它。我怎样才能做到这一点?

现在我的代码添加到列表视图,但不保存它。

ListView listView;
Button AddWebsiteBtn;
EditText WebsiteName;
String[] ListOfWebsites = new String[]{};
SharedPreferences preferences;
SharedPreferences.Editor editor;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add);
    listView = (ListView) findViewById(R.id.list_of_websites);
    AddWebsiteBtn = (Button) findViewById(R.id.btn_submit);
    WebsiteName = (EditText) findViewById(R.id.website_name);

    //using this part to add it to listview, maybe will need to remove it when shared preferences will work
    final List< String > ListElementsArrayList = new ArrayList< String >
            (Arrays.asList(ListOfWebsites));

    final ArrayAdapter < String > adapter = new ArrayAdapter< String >
            (AddActivity.this, android.R.layout.simple_list_item_1, …
Run Code Online (Sandbox Code Playgroud)

android listview arraylist sharedpreferences

3
推荐指数
1
解决办法
3914
查看次数

标签 统计

android ×1

arraylist ×1

listview ×1

sharedpreferences ×1