Answer the question
In order to leave comments, you need to log in
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;
}
...
}
FillingCashSettings.init(cashList.get(position), cashListAdapter); // тут загружается конкретная сущность ну и адаптер в придачу, чтобы проводить с ним некие манипуляции
intent = new Intent(getApplicationContext(), FillingCashSettings.class);
startActivity(intent);
@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);
}
});
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();
}
});
notifyDataSetChanged()
, but it did not help. Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question