0

I have some problem with saving the text from an EditText.

Here is the code:

String lista;
EditText bevasarlolista = null;
bevasarlolista = view.FindViewById<EditText>(Resource.Id.bevasarlo);

if (items[position] == "Bevásárlólista")
{
    Button mentes = view.FindViewById<Button>(Resource.Id.hozzaad);
    bevasarlolista.Text = lista;

    mentes.Click += bevasarlolistaMentese;
}

private void bevasarlolistaMentese(object sender, EventArgs e)
{
    lista = bevasarlolista.Text;

    Toast.MakeText(Application.Context, bevasarlolista.Text, ToastLength.Long).Show();
}

So the problem is that when I write something in that editText, and than press the 'mentes' button the toast text appears, but its empty, meaning that my editText is empty too and i don't know how sould i save the editText.text

Thanks for the help!

user1506104
  • 6,554
  • 4
  • 71
  • 89
  • Possible duplicate of [Android Shared preferences example](https://stackoverflow.com/questions/23024831/android-shared-preferences-example) – Salman500 May 29 '18 at 09:37

2 Answers2

0

To make a text blocked you have to change the code like this:

String lista;
EditText bevasarlolista = null;
bevasarlolista = view.FindViewById<EditText>(Resource.Id.bevasarlo);

if (items[position] == "Bevásárlólista")
        {
    Button mentes = view.FindViewById<Button>(Resource.Id.hozzaad);
    bevasarlolista.setText(lista);

    mentes.Click += bevasarlolistaMentese;
}

private void bevasarlolistaMentese(object sender, EventArgs e)
{
    lista = bevasarlolista.Text;

    Toast.MakeText(Application.Context, bevasarlolista.Text, ToastLength.Long).Show();
}

Embedding the text in java This is an overview. For more information, see this link how to save data in editText using Shared Preferences in android

user1506104
  • 6,554
  • 4
  • 71
  • 89
Ali Tooshmalani
  • 241
  • 2
  • 7
0

So it turned out that i was just being dumb.

i sould have given value to the edittext inside the if()

BAD

string lista;
EditText bevasarlolista = null;
bevasarlolista = view.FindViewById<EditText>(Resource.Id.bevasarlo);

if (items[position] == "Bevásárlólista")
     {

     }

GOOD string lista; EditText bevasarlolista = null;

if (items[position] == "Bevásárlólista")
     {
         bevasarlolista = view.FindViewById<EditText>(Resource.Id.bevasarlo);
     }