0
public class MainActivity extends AppCompatActivity {
   
GridView gridView;
Toolbar toolbar; 
Dialog dialog;
    AlertDialog alertDialog;
    private ArrayList<String> arr; //to store the name of list of title

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

  //arraylist of our title names
        arr = new ArrayList<>(); 
        gridView = findViewById(R.id.gv); //grid view which contains list of names of title
        adaptergv ad = new adaptergv(this,arr);
        gridView.setAdapter(ad);

    Add.setOnClickListener(new View.OnClickListener() { //listener which adds title name in arraylist

            @Override
            public void onClick(View view) {

                String s = name.getText().toString(); //getting edittext content as string
                int sum = 0; //to check if there is alphabets in edittext
                for (int i = 0;i<s.length();i++){ //whole for loop will check if there is something written in edittext
                    String a = String.valueOf(s.charAt(i)); //value of string s at i index
                    if(!a.equals(" ")){ // true if there is character at certain index
                        sum+=1;
                    }
                }

                if( !s.equals("")&&sum!=0 ){ // if in edittext there is something written

                   arr.add(s); //adding new title
                  dialog.dismiss(); //dismising the dialog box
                    name.setText(null);// resetting edittext to null for 2nd time add got clicked
                    alert.setText(null); // resetting alert message to null for 2nd time add get clicked
                }
                else {
                    alert.setText("Enter the name"); //if user didnt put anything in name then display this message
                }

            }
        });

I have been try to create a app like notes app in which user will add a name in list by clicking add button after that as u can see in code ,name will be store in arraylist so my problem is how can i store that title names after app is closed like let's say i added two names in listenter image description here and then when i reopened those two title should be there and after that i added two more names and i closed and reopend all four of them should be stored and there in app enter image description here(i am newbie and couln't find solution )

0 Answers0