I have made listViewAdapter which gets data from three EditText and display on it but the problem is, if i click the add button then the first entry is over written by the new entries .i want to add the data to be in the list.
Here is my android code:
public class List extends AppCompatActivity {
private EditText etItem;
private EditText etQty;
private EditText etRate;
public static String item;
public static String qty;
public static String rate;
private ArrayList<HashMap> list;
public listviewAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
etItem=(EditText)findViewById(R.id.etItem);
etQty=(EditText)findViewById(R.id.etQty);
etRate=(EditText)findViewById(R.id.etRate);
item=etItem.getText().toString();
qty=etQty.getText().toString();
rate=etRate.getText().toString();
Button bAdd=(Button)findViewById(R.id.bAdd);
bAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ListView lview = (ListView) findViewById(R.id.listview);
populateList();
listviewAdapter adapter = new listviewAdapter(List.this, list);
lview.setAdapter(adapter);
adapter.notifyDataSetChanged();
etItem.setText("");
etQty.setText("");
etRate.setText("");
}
});
}
private void populateList() {
list = new ArrayList<HashMap>();
item=etItem.getText().toString();
qty=etQty.getText().toString();
rate=etRate.getText().toString();
HashMap temp = new HashMap();
temp.put(FIRST_COLUMN,"");
temp.put(SECOND_COLUMN, item);
temp.put(THIRD_COLUMN, qty);
temp.put(FOURTH_COLUMN, rate);
list.add(temp);
}