Note that there are some explanatory texts on larger screens.

plurals
  1. POSave ArrayList to memory and read it
    primarykey
    data
    text
    <p>i got this code into my app, i need that when you click "OK" or "Borrar" on the pop up Dialog save the ArrayList "al" so when i close the app and open it again, the list have the previous items, i tried so hard but i cant figure it out, i started with java 6 days ago so i don't have much idea, thanks!</p> <pre><code>public class Iniciado extends Activity { TextView tv3; ListView listView; final Context context = this; final ArrayList&lt;String&gt; al = new ArrayList&lt;String&gt;(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.iniciado); conseguirdatos(); tv3=(TextView)findViewById(R.id.tv3); Bundle bolsar = getIntent().getExtras(); tv3.setText("Bienvenido "+ bolsar.getString("NombreKey")); listView = (ListView)findViewById(R.id.list); // Defined Array values to show in ListView final ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, android.R.id.text1, al); // Assign adapter to ListView listView.setAdapter(adapter); // ListView Item Click Listener listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { // ListView Clicked item index final int itemPosition = position; // ListView Clicked item value String itemValue = (String) listView.getItemAtPosition(position); // Show Alert Toast.makeText(getApplicationContext(), "Position :"+itemPosition+" ListItem : " +itemValue , Toast.LENGTH_LONG) .show(); // Make Dialog final Dialog dialog = new Dialog(context); dialog.setContentView(R.layout.cambiar); dialog.setTitle("Editar evento"); // set the custom dialog components - text, image and button final EditText editar = (EditText)dialog.findViewById(R.id.eteditar); editar.setText(itemValue); Button okBtn = (Button) dialog.findViewById(R.id.okbtn); Button borrarBtn = (Button) dialog.findViewById(R.id.borrarbtn); // if button is clicked, close the custom dialog okBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String recuperado = editar.getText().toString(); al.set(itemPosition, recuperado); ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(Iniciado.this, android.R.layout.simple_list_item_1, android.R.id.text1, al); adapter.notifyDataSetChanged(); dialog.dismiss(); } }); borrarBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { al.remove(itemPosition); adapter.notifyDataSetChanged(); dialog.dismiss(); } }); dialog.show(); } }); } private void conseguirdatos() { if(al.size() == 0){ al.add("C"); al.add("A"); al.add("E"); al.add("B"); al.add("D"); al.add("F"); al.add("C"); al.add("A"); al.add("E"); al.add("B"); al.add("D"); al.add("F"); al.add("C"); al.add("A"); al.add("E"); al.add("B"); al.add("D"); al.add("F"); al.add("C"); al.add("A"); al.add("E"); al.add("B"); al.add("D"); al.add("F"); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload