Hot questions for Using Android EditText in android listview

Question:

Here is the xml (activity_matches.xml) that displays the output in the screen shot below in an EditText object named txaMatches:

<EditText
    android:id=                     "@+id/txaMatches"
    android:text=                   ""

    android:scrollbars=             "vertical"
    android:layout_below=           "@+id/pattern"
    android:textColor=              "@color/yellow_foreground"
    android:textSize=               "@dimen/matches_text"
    android:focusable="false"
    android:inputType="textMultiLine"

    android:layout_width=           "wrap_content"
    android:layout_height=          "wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentEnd=  "true"
    tools:ignore=                   "LabelFor"
    android:typeface="monospace"
    android:focusableInTouchMode="false"
    android:paddingEnd="@dimen/matches_padding"
    android:paddingStart="@dimen/matches_padding"
    />

I would like the contents of this multiline EditText object to scroll smoothly with acceleration if the user swipes inside it.

Here's how I fill txaMatches (using doInBackground). This is the only place in Java code that I refer to it (of course I also define and initialize it in Java):

protected void onProgressUpdate(String... progress)
{
  for (int i = 0; i < progress.length; i++)
    if(progress[i].length() > 1) MatchesActivity.txaMatches.append("\n" + progress[i]);
    else                         MatchesActivity.showLetter("Reading " + progress[i].charAt(0));
}

Is this an easy change to be made in xml?

Should I be using a ListView? Should the EditText be inside a ListView?

Am I going to have to write some Java code?

Given the small amount of code I've provided, I don't expect many details. Just an overview of what to Google would be a good start.


Answer:

Pretty easy (thanks to Fllo's THIRD link). (The first was no help; the second focuses on Java code and the ScrollView class and is more involved than the third, which focuses on xml and was perfect for my situation (and required only changing the type of txaMatches to TextView):

start of new code

<ScrollView
    android:layout_alignParentStart="true"
    android:layout_alignParentEnd=  "true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

end of new code except for closing tag

<TextView
    android:id=                     "@+id/txaMatches"
    android:scrollbars=             "vertical"
    android:layout_width=           "wrap_content"
    android:layout_height=          "wrap_content"
    />
</ScrollView>

Question:

So the picture will give you a better understanding of the problem:

See , i added 3 TextView to the left ListView and 3 EditText to the right ListView but they are not on the same line. So how do i solve it?

My related to the issue XML:

 <LinearLayout
            android:id="@+id/inner_linear_layout_id"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_below="@id/date_picker_id"
            android:baselineAligned="false"
            android:orientation="horizontal"
            android:weightSum="1" >

        <ListView
            android:id="@+id/dates_list_view_id"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.5" 
            />

        <ListView
            android:id="@+id/comments_list_view_id"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.5" 
            />
    </LinearLayout>

My related to the issue Java:

arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,datesListView.getId());
datesListView.setAdapter(arrayAdapter);
commentsListView.setAdapter(arrayAdapter);


date.setTextSize(20);
datesListView.addFooterView(date);
commentText.setId(998);
commentText.setInputType(EditorInfo.TYPE_CLASS_TEXT);       
commentText.setHint("Add a comment");
commentText.setTextSize(15);

commentsListView.addFooterView(commentText); 

date is a TextView and commentText is an EditText.


Answer:

Ok, here's one solution. Of course there are many other possible solutions.

Here's the XML for the list item. It describes the view for a single entry in your list. Here it is built with a TextView and an EditText:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="horizontal"
              android:layout_width="match_parent"
              android:layout_height="wrap_content">

    <TextView
            android:id="@+id/text_datetime"
            android:text="8:20p.m."
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

    <EditText
            android:id="@+id/edit_comment"
            android:text="no comment"
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

</LinearLayout>

That's the XML for the main activity which actually contains the ListView itself. But it does not indicate how the children (the list items) will look like because that's defined by the XML above:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
        >
    <ListView
            android:id="@+id/my_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />
</LinearLayout>

And that's the code for the MainActivity which includes some demo data that is bound to the ListView. This actually connects the ListView with it's items and the corresponding XML for the ListView Items:

package com.example.myapp;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.*;

public class MyActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ListView list = (ListView)findViewById(R.id.my_list);
        if (list != null) {
            final List<DemoItem> demoList = new ArrayList<DemoItem>();

            final SimpleDateFormat hourDateFormat = new SimpleDateFormat("HH:mm", Locale.getDefault());
            final Calendar c = Calendar.getInstance();
            final Date now = c.getTime();
            final String now_ = hourDateFormat.format(now);

            demoList.add(0, new DemoItem(now_, "first comment"));
            demoList.add(1, new DemoItem(now_, "second comment"));
            demoList.add(2, new DemoItem(now_, "third comment"));

            DemoAdapter adapter = new DemoAdapter(this, demoList);
            list.setAdapter(adapter);
        }
    }

    class DemoItem {
        public String datetime;
        public String comment;

        public DemoItem(String datetime, String comment) {
            this.datetime = datetime;
            this.comment = comment;
        }
    }

    class DemoAdapter extends ArrayAdapter<DemoItem> {

        public DemoAdapter(Context context, List<DemoItem> items) {
            super(context, R.layout.list_item, items);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            if (convertView == null)
                convertView = getLayoutInflater().inflate(R.layout.list_item, null);

            DemoItem item = super.getItem(position);

            EditText editComment = (EditText)convertView.findViewById(R.id.edit_comment);
            if (editComment != null)
                editComment.setText(item.comment);

            TextView txtDatetime = (TextView)convertView.findViewById(R.id.text_datetime);
            if (txtDatetime != null)
                txtDatetime.setText(item.datetime);

            return convertView;
        }
    }
}

That's how it looks like in the end:

And if you won't use a ListView, then here's a RelativeLayout that does the same. But it's not dynamically and not bound to any adapter:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <TextView
            android:id="@+id/text_datetime1"
            android:text="8:20p.m."
            android:layout_toLeftOf="@+id/edit_comment1"
            android:layout_alignBaseline="@+id/edit_comment1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>

    <EditText
            android:id="@+id/edit_comment1"
            android:text="no comment"
            android:layout_alignParentRight="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

    <TextView
            android:id="@+id/text_datetime2"
            android:text="8:20p.m."
            android:layout_toLeftOf="@+id/edit_comment2"
            android:layout_alignBaseline="@+id/edit_comment2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>

    <EditText
            android:id="@+id/edit_comment2"
            android:text="no comment"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/edit_comment1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

    <TextView
            android:id="@+id/text_datetime3"
            android:text="8:20p.m."
            android:layout_toLeftOf="@+id/edit_comment3"
            android:layout_alignBaseline="@+id/edit_comment3"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>

    <EditText
            android:id="@+id/edit_comment3"
            android:text="no comment"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/edit_comment2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

</RelativeLayout>

Question:

I'm getting values for ListItem from String array and showing them as ListView, also I had added EditText field so that when user enters some text then listview shows only matching items. My concern is that when User click on any listview item the text from this item must be shown inside edittext field, I had tried so many methods like, onitemclicklistener, viewgroup but hadn't get succeded, each time getting errors. Below is my code and please help me with this. MainActivity.java

private ListView lv;
    // Listview Adapter
    ArrayAdapter<String> adapter;
    // Search EditText
    EditText inputSearch;
    // ArrayList for Listview
    ArrayList<HashMap<String, String>> productList;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // Listview Data
        final String products[] = getResources().getStringArray(R.array.Countreis);
        lv = (ListView) findViewById(R.id.list_view);
        inputSearch = (EditText) findViewById(R.id.inputSearch);
        // Adding items to listview
        adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.product_name, products);
        lv.setAdapter(adapter);
        lv.setVisibility(View.GONE);
        inputSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
                // When user changed the Text
                MainActivity.this.adapter.getFilter().filter(cs);
                if(cs.length()== 0){
                    lv.setVisibility(View.GONE);
                }else{
                lv.setVisibility(View.VISIBLE);
                }
            }
            @Override
            public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                    int arg3) {
                // TODO Auto-generated method stub
            }
            @Override
            public void afterTextChanged(Editable arg0) {
                // TODO Auto-generated method stub
            }
        });

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
     <!-- Editext for Search -->
    <EditText android:id="@+id/inputSearch"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Search products.."
        android:inputType="textVisiblePassword"/>
    <!-- List View -->

    <ListView
        android:id="@+id/list_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
 </LinearLayout>

list_item.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <!-- Single ListItem -->
 <!-- Product Name -->
    <TextView android:id="@+id/product_name"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dip"
        android:textSize="16sp"
        android:textStyle="bold"/>   
 </LinearLayout>

String Array:

    <string-array name="Countreis">
        <item >India</item>
        <item >Pakistan</item>
        <item >Bnagladesh</item>
        <item >Nepal</item>
        <item >China</item>
        <item >Russia</item>
        <item >America</item>
        <item >Ingland</item>
        <item >Japan</item>
        <item >Arab emirat</item>
        <item >Saudi Arabia</item>
        <item >Austrelia</item>
        <item> Kuwiat</item>
        <item >Israil</item>
   </string-array>

Answer:

Implement ListView item click listener :

lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
         inputSearch.setText(adapter.getItem(position));
    }
});

Question:

I have two EditText, I want to get edittext's value when I click button, and display that value in a custom layout. I included MainActivity.java and CustomAdapter.java and tried it many times in different ways but none of them worked.Please help.

MainActivity.java

    add_button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String ed_text_1=credit_edt.getText().toString();
            String ed_text_2=gpa_edt.getText().toString();
            double d_value_1=Double.parseDouble(ed_text_1);
            double d_value_2=Double.parseDouble(ed_text_2);
            double result=d_value_1+d_value_2;

            CustomAdapter adapter=new CustomAdapter(MainActivity.this,d_value_1,d_value_2,result);
            listView.setAdapter(adapter);

            credit_edt.setText("");
            gpa_edt.setText("");
        }
    });

CustomAdapter.java

class CustomAdapter extends BaseAdapter {

double str1;
double str2;
double ans;
Context context;
private LayoutInflater inflater;

public CustomAdapter(Context context,double str1, double str2, double ans) {
    this.context = context;
    this.str1 = str1;
    this.str2 = str2;
    this.ans = ans;
}

@Override
public int getCount() {
    return 0;
}

@Override
public Object getItem(int position) {
    return null;
}

@Override
public long getItemId(int position) {
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    if(convertView==null)
    {
        inflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView=inflater.inflate(R.layout.output_layout,parent,false);
    }
    TextView txt1=(TextView) convertView.findViewById(R.id.crt_c_id);
    TextView txt2=(TextView) convertView.findViewById(R.id.gp_c_id);
    TextView txt3=(TextView) convertView.findViewById(R.id.tl_c_id);

    String s1=Double.toString(str1);
    String s2=Double.toString(str2);
    String s3=Double.toString(ans);

    txt1.setText(s1);
    txt2.setText(s2);
    txt3.setText(s3);
    return convertView;
}

Answer:

Check your custom adapter arguments

Pass value from Activity

 CustomAdapter adapter=new CustomAdapter(MainActivity.this,d_value_1,d_value_2,result);

And get it in to adapter

 CustomAdapter(double[] str1, double[] str2, double[] ans, Context context)

Check your argument datatype and sequence:- From activity you pass context as a first argument and in adapter you get it in the last

Happy Coding!!!

Question:

I want to make a clickable listView with editable editText. I have a custom list adapter.java, custom list item.xml, mainActivity.java.

I tried 1. android:descendantFocusability="blocksDescendants" => failed. can't edit editText. 2. editText android:focusable/enable/clickable = true => failed. can't click listView Item 3. getView{editText.onClickListener} =>failed.

I want to EDITABLE editText, not just clickable editText & Clickable listView(listItem). please help.

customitem.XML

...

   <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:gravity="center_vertical"
    android:descendantFocusability="blocksDescendants"
    >

    //android:descendantFocusability="blocksDescendants" doesn't work

    <EditText 
        android:id="@+id/tvItem"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:textSize="20sp"
        android:textColor="#ffffff"
        android:layout_marginLeft="25dp"
        android:textStyle="bold"
        android:background="@null"
        android:shadowColor="@color/shadow"
        android:shadowDx="3"
        android:shadowDy="3"
        android:shadowRadius="1"
        android:imeOptions="actionDone"
        android:inputType="text"
        android:focusable="true"
        />
    <TextView
        android:id="@+id/tvItemCount"
        android:layout_width="@dimen/list_height"
        android:layout_height="70dp"
        android:layout_alignParentRight="true"
        android:textColor="#ffffff"
        android:textSize="22dp"
        android:text="6"
        android:background="#3300b7ff"
        android:gravity="center_vertical|center_horizontal"
        android:shadowColor="@color/shadow"
        android:shadowDx="3"
        android:shadowDy="3"
        android:shadowRadius="1"
        android:textStyle="bold"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:background="@color/dark_shadow" >

    </LinearLayout>
</RelativeLayout>

...


Answer:

After few attempts which I've made by myself, I've asked uncle Google about your problem. Do you know, what he said?

ListView aren't able to handle EditText view well. If many people couldn't resolve this issue before, maybe you will consider some 'workaround' like this desribed HERE. It is an answer to other issue, but probably even if you will fix above problem, you will meet this one.

In brief @Andrew recommends to use ScrollLayout with simple LinearLayout inside instead of ListView. In onCreate method he inflates the View used for list items and add it to LinearLayout, and store this in ArrayList as well, to save data to every view later.

I know it isn't solution for your problem, but maybe it let you a lot of time, which you will spend looking for any reasonable solution.

Edit

It is funny. Inspired by @Rishabh Srivastava link I've tried to find some solution (I know, I'm a little bit stubborn).

I've create adapter layout - RelativeLayout, which is fully filled by Button and above it (I mean literally above it - in Z axis) I've placed EditText view. I thought that edittext will handle click on it and button will handle clicks outside of edittext view. Unfortunately 'click' event propagate through all of views - so by clicking on edittext, we will click on button as well.

I thought I am smarter than everybody so I used OnTouchListener - we can handle single 'touch' event and return true value, as information to OS that we handle it.

And you know what? I've met problem exactly the same like desribed in above link:

When I click on an EditText, the virtual keyboard shows itself, but the EditText loses focus and I have to click the EditText again.

I hope you don't want lost your time any more;)

Question:

So whenever I scrolldown on the list view, and put a value on the editText, the value of the editText disappears when scrolling down. I am using a custom layout for my listview.

I want to prevent the EditText value from disappearing whenever the row of the listview goes out of the screen.

add_food_intake.java

public class add_food_intake extends AppCompatActivity {
    SQLiteDatabase db, Foods;
    SQLiteOpenHelper helper1, helper;
    ArrayList<String> listItem;
    ArrayAdapter adapter;
    ListView foodview;
    SwipeRefreshLayout swiper;
    EditText editText1;

    int id;
    String str, str1, age1, foodname, foodtype, grams, kCal, carbohydrates;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_food_intake);
        helper = new FoodDB(this);
        editText1 = findViewById(R.id.editText1);
        db = helper.getReadableDatabase();
        helper1 = new FoodDB(this);
        Button aButton = (Button) findViewById(R.id.addButton);
        foodview = (ListView) findViewById(R.id.fooditems);
        listItem = new ArrayList<>();
        viewData();
        foodview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                String text = foodview.getItemAtPosition(i).toString();
                Toast.makeText(add_food_intake.this, "" + text, Toast.LENGTH_SHORT).show();
            }
        });
        Button mShowDialog = (Button) findViewById(R.id.customButton);
        mShowDialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                AlertDialog.Builder mBuilder = new AlertDialog.Builder(add_food_intake.this);
                final View mView = getLayoutInflater().inflate(R.layout.custom_food_intake_dialog, null);
                final EditText FoodName = (EditText) mView.findViewById(R.id.food_name);
                final EditText ServingSize = (EditText) mView.findViewById(R.id.serving_size);
                final EditText Fats = (EditText) mView.findViewById(R.id.total_fat);
                final EditText Calories = (EditText) mView.findViewById(R.id.calories);
                final EditText Carbohydrates = (EditText) mView.findViewById(R.id.carbohydrates);
                final EditText Protein = (EditText) mView.findViewById(R.id.protein);
                final RadioButton go1 = (RadioButton) mView.findViewById(R.id.go);
                final RadioButton grow1 = (RadioButton) mView.findViewById(R.id.grow);
                final RadioButton glow1 = (RadioButton) mView.findViewById(R.id.glow);
                final CheckBox breakfast = (CheckBox) mView.findViewById(R.id.breakfast_box);
                final CheckBox lunch = (CheckBox) mView.findViewById(R.id.lunch_box);
                final CheckBox dinner = (CheckBox) mView.findViewById(R.id.dinner_box);
                final Button button = (Button) mView.findViewById(R.id.addfromcustomfood);
                button.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        String name = FoodName.getText().toString();
                        String size = ServingSize.getText().toString();
                        String fats = Fats.getText().toString();
                        String calories = Calories.getText().toString();
                        String carbs = Carbohydrates.getText().toString();
                        String protein = Protein.getText().toString();
                        String type = "";
                        ArrayList<String> meal = new ArrayList<>();
                        String add = meal.toString();
                        if (go1.isChecked()) {
                            type = go1.getText().toString();
                        } else if (grow1.isChecked()) {
                            type = grow1.getText().toString();
                        } else if (glow1.isChecked()) {
                            type = glow1.getText().toString();
                        }
                        switch (mView.getId()) {
                            case R.id.breakfast_box:
                                if (breakfast.isChecked()) {
                                    meal.add("Breakfast");
                                } else {
                                    meal.remove("Breakfast");
                                }
                            case R.id.lunch_box:
                                if (lunch.isChecked()) {
                                    meal.add("Lunch");
                                } else {
                                    meal.remove("Lunch");
                                }
                            case R.id.dinner_box:
                                if (dinner.isChecked()) {
                                    meal.add("Dinner");
                                } else {
                                    meal.remove("Dinner");
                                }
                        }
                        if (!name.isEmpty() && !size.isEmpty() && !fats.isEmpty() && !calories.isEmpty() && !protein.isEmpty() && !carbs.isEmpty()
                                && (go1.isChecked() || grow1.isChecked() || glow1.isChecked())) {

                            insertData(type, name, size, fats, calories, carbs, protein, add);
                            Toast.makeText(add_food_intake.this, "Food has ben Added!", Toast.LENGTH_SHORT).show();
                            refreshData();

                        } else {
                            Toast.makeText(add_food_intake.this, "Fail", Toast.LENGTH_SHORT).show();
                        }
                    }
                });

                mBuilder.setView(mView);
                AlertDialog dialog = mBuilder.create();
                dialog.show();
            }
        });


    }

    public void insertData(String type, String name, String size, String fats, String calories, String carbs, String protein, String add) {
        db = helper1.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put("type", type);
        contentValues.put("name", name);
        contentValues.put("grams", size);
        contentValues.put("cal", calories);
        contentValues.put("fat", fats);
        contentValues.put("carbohydrates", carbs);
        contentValues.put("protein", protein);
        contentValues.put("meal_type", add);
        long id = db.insert("Food_Items", null, contentValues);
    }

    private void viewData() {
        Cursor cursor = db.rawQuery("SELECT * FROM Food_Items", null);

        if (cursor.getCount() == 0) {
            Toast.makeText(add_food_intake.this, "No data to show", Toast.LENGTH_SHORT).show();
        } else {
            while (cursor.moveToNext()) {
                listItem.add(cursor.getString(cursor.getColumnIndex("name")));
            }
            adapter = new MySimpleArrayAdapter(add_food_intake.this, listItem);
            foodview.setAdapter(adapter);
        }
        cursor.close();

    }

    public void refreshData() {
        listItem.clear();
        viewData();
        foodview.setAdapter(adapter);
    }

    /**
     * This adapter will create your list view row by row
     */
    public class MySimpleArrayAdapter extends ArrayAdapter<String> {

        private final Context context;
        private final ArrayList<String> values;

        public MySimpleArrayAdapter(Context context, ArrayList<String> values) {

            super(context, R.layout.add_food_intake_layout, values);

            this.context = context;
            this.values = values;

        }

        /**
         * Here we go and get our rowlayout.xml file and set the textview text.
         * This happens for every row in your listview.
         */
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            View rowView = inflater.inflate(R.layout.add_food_intake_layout, parent, false);

            TextView textView = (TextView) rowView.findViewById(R.id.textView1);
            EditText editText = (EditText) rowView.findViewById(R.id.editText1);

            // Setting the text to display
            textView.setText(values.get(position));

            return rowView;
        }
    }
}

add_food_intake_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:text="Name"
        android:textColor="@color/Black"
        android:textSize="16dp" />

    <RelativeLayout
        android:id="@+id/layout2"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/textView1"
        android:orientation="vertical">

        <TextView
            android:id="@+id/textView2"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:text="Value"
            android:textColor="@color/MainGreen"
            android:textSize="18dp" />
    </RelativeLayout>

    <RelativeLayout
        android:background="@drawable/edittext_box"
        android:id="@+id/layout3"
        android:layout_width="100dp"
        android:layout_height="59dp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true"
        android:layout_marginEnd="20dp"
        android:orientation="vertical">

        <EditText
            android:id="@+id/editText1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:layout_marginStart="0dp"
            android:layout_marginTop="0dp"
            android:inputType="number"
            android:singleLine="true"
            android:textAlignment="center"
            android:textColor="@color/Black"
            android:textSize="18dp" />
    </RelativeLayout>

</RelativeLayout>

Answer:

This is because in your getView method you are creating a new view every time the adapter requests one. You should check if you can re-use the already inflated view.

Docs of the method -

/**
 * Get a View that displays the data at the specified position in the data set. You can either
 * create a View manually or inflate it from an XML layout file. When the View is inflated, the
 * parent View (GridView, ListView...) will apply default layout parameters unless you use
 * {@link android.view.LayoutInflater#inflate(int, android.view.ViewGroup, boolean)}
 * to specify a root view and to prevent attachment to the root.
 * 
 * @param position The position of the item within the adapter's data set of the item whose view
 *        we want.
 * @param convertView The old view to reuse, if possible. Note: You should check that this view
 *        is non-null and of an appropriate type before using. If it is not possible to convert
 *        this view to display the correct data, this method can create a new view.
 *        Heterogeneous lists can specify their number of view types, so that this View is
 *        always of the right type (see {@link #getViewTypeCount()} and
 *        {@link #getItemViewType(int)}).
 * @param parent The parent that this view will eventually be attached to
 * @return A View corresponding to the data at the specified position.
 */
 View getView(int position, View convertView, ViewGroup parent);

Basically, you should only inflate a new view if convertView is null else re-use it.

This will solve the resetting problem. But, now edit texts might start to duplicate. For this, you'll have to implement a ViewHolder pattern and save the entered data by adding and removing textwatchers on the edittexts -

Follow this -

Working with ArrayAdapter - https://guides.codepath.com/android/Using-an-ArrayAdapter-with-ListView

Duplicate edittexts - Android ListView with EditText values duplicating with TextWatcher