A
A
Arti-Jack2017-04-30 00:13:20
Android
Arti-Jack, 2017-04-30 00:13:20

How to solve the issue with refreshing List Adapter and ListView?

I'm trying to make an application where there is a list of elements (ListView) and each element from the list has two values. When you click on this list, a new window (Intent) appears, where you can change the fields. And if after that you go to the previous activity, then the fields of the elements, of course, should change.
I tried to do it with ListView and implementing my own adapter.
There is also a certain entity like Cash:

public class Cash {

    private static HashMap<String, Integer> TABLE = new HashMap<>();
    private int coast;
    private int income;
    private int id;
    private String name;
 
    public Cash(int coast, int income, int id, String name) {
        this.coast = coast;
        this.income = income;
        this.id = id;
        this.name = name;
    }

    public int getCoast() {
        return coast;
    }

    public int getIncome() {
        return income;
    }

    public int getId() {
        return id;
    }

    ...
   
}

And in the listeners to my adapter I do the following:
I load the list item and the adapter
FillingCashSettings.init(cashList.get(position), cashListAdapter); // тут загружается конкретная сущность ну и адаптер в придачу, чтобы проводить с ним некие манипуляции

And I call the FillingCashSettings activity with the Intent, hoping to fill in the values.
intent = new Intent(getApplicationContext(), FillingCashSettings.class);
          startActivity(intent);

Here is the entire onCreate code:
@Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cash_settings);

        listView = (ListView) findViewById(R.id.cashListView);
        cashList = new ArrayList<>();
        cashSettings = new FillingCashSettings();

        // Закрепляем слушателя на listView
        for (int i = 0; i < settings.length; i++) {
            cashList.add(new Cash(0, 0, i, settings[i]));
        }

        cashListAdapter = new CashListAdapter(getApplicationContext(), cashList);
        listView.setAdapter(cashListAdapter);

        // Закрепление хэндлеров
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(
                        getApplicationContext(),
                        "clicked " + view.getTag(),
                        Toast.LENGTH_SHORT
                ).show();

                FillingCashSettings.init(cashList.get(position), cashListAdapter);
                intent = new Intent(getApplicationContext(), FillingCashSettings.class);
                startActivity(intent);
            }
        });

Then in the button handler I try to change the value of the previously loaded entity
enterButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String income = editText.getText().toString();
                cash.setIncome(Integer.parseInt(income));
                Toast.makeText(getApplicationContext(), cash.getName() + cash.getIncome(), Toast.LENGTH_LONG).show();
            }
        });

And as debugging shows, it seems like it has changed, but at the same time, the adapter sheet has the same value as before.
And I want to say right away that I even tried notifyDataSetChanged(), but it did not help.
Here is a screenshot of the application itself:
b6d3583ef7e042018e9e76b778c393a9.png
How do I make the ListView update?
PS: I want to say right away that I am very weak in androyd, since I just started to study it, so I count on your understanding!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
7
7365656c65, 2017-05-05
@73656c6565

As far as I understand, you need to transfer values ​​​​between the activations, this is done by key.
Link to lesson .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question