mercredi 29 juin 2016

EditText losing its value once the keyboard is minimized

I have created my form programmatically as I depend on values present in my DB.

mydb = new DatabaseAdapter(this);
Cursor cursor = mydb.getAllJuice();
calculate = (Button) findViewById(R.id.button1);
li = new ArrayList<String>();

while (cursor.moveToNext()) {
    int cid = cursor.getInt(0);
    String id = Integer.toString(cid);
    String name = cursor.getString(1);
    String price = cursor.getString(2);
    //li.add(price);
    names.add(name); //this adds an element to the list.
    desc.add(price); //this adds an element to the list.
    qty.add("");
}

JuiceAdapter customList = new JuiceAdapter(this, names, desc, qty);

listView = (ListView) findViewById(R.id.listView1);
listView.setAdapter(customList);

In my for I have 2 TextViews that are being filled according to the values from DB (name and price of an item) and an EditText which depends on the value that the user will insert.

In my main.xml i have a call for the listView:

 <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button1"
        android:layout_alignParentLeft="true"
        android:layout_marginTop="30dp" >
    </ListView>

Which uses the list.xml which is as below:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent" >

    <TextView
        android:id="@+id/label1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@+id/label1"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="8dp"
        android:clickable="false"
        android:textSize="30dp" />


    <TextView
        android:id="@+id/price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="8dp"
        android:text="@+id/price"
        android:clickable="false"
        android:textSize="30dp" />

    <EditText
        android:id="@+id/qty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="8dp"
        android:inputType="number"
        android:textSize="30dp"
        android:ems="7"
        android:clickable="true"/>

</LinearLayout>

First the click on the EditText is not being easy to open the Keyboard. And once the keyboard is open and I insert a value into the EditText and then when I minimize the keyboard the values are lost.

Any ideas please why I am losing the values and how I can make the click easier?

Testing on Virtual device

Aucun commentaire:

Enregistrer un commentaire