#
whycq
2025-01-21 9c414520fd00319683a0021bb512f5003aff2800
app/src/main/java/com/example/agvcontroller/EditeActivity.java
@@ -1,6 +1,6 @@
package com.example.agvcontroller;
import android.content.Intent;
import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
@@ -22,12 +22,13 @@
public class EditeActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private List<Item> items;
    private List<AGVCar> items;
    private EditeAdapter adapter;
    private SharedPreferences sharedPreferences;
    private AppCompatImageButton addItem;
    private Button confirm;
    @SuppressLint("WrongViewCast")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
@@ -52,7 +53,7 @@
            @Override
            public void onClick(View v) {
                items.add(new Item("", "", 0, "", 0));
                items.add(new AGVCar("", "", 0, "", 0));
                adapter.notifyDataSetChanged();
                Log.d("items", items.toString());
            }
@@ -81,11 +82,11 @@
        editor.apply();
    }
    private List<Item> loadItemsFromSharedPreferences() {
    private List<AGVCar> loadItemsFromSharedPreferences() {
        Gson gson = new Gson();
        String json = sharedPreferences.getString("items", null);
        if (json != null) {
            Type type = new TypeToken<List<Item>>(){}.getType();
            Type type = new TypeToken<List<AGVCar>>(){}.getType();
            return gson.fromJson(json, type);
        }
        return new ArrayList<>();