M
M
MrStuff882016-01-11 20:26:34
Android
MrStuff88, 2016-01-11 20:26:34

How to get listview from Adapter?

I created my own adapter by deriving from ArrayAdapter. When the user clicks the button, a row is added to the ListView. When an application is removed from the phone stack, the list is not saved. How can I get the ListView list from the adapter, save it, and set the list the next time the application starts
? Here is the adapter:

public class MyAdapter extends ArrayAdapter {
ArrayList nameInfo = new ArrayList();
public MyAdapter(Context context, ArrayList nameInfo) {
super(context, 0, nameInfo);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Info data = getItem(position);
if (convertView == null) {
convertView =
LayoutInflater.from(getContext()).inflate(R.layout.row, parent, false);
}
TextView column1 = (TextView) convertView.findViewById(R.id.col1);
TextView column2 = (TextView) convertView.findViewById(R.id.col2);
column1.setText(data.par1);
column2.setText(data.par2);
return convertView;
}
}

Here is the adapter and the list in the main activity
MyAdapter = new MyAdapter(this, nameInfo);
ListView lvMain = (ListView) findViewById(R.id.lvMain);
lvMain.setAdapter(MyAdapter);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Artemov, 2016-01-13
@roman_art

Since your adapter uses a special data structure for display, you will have to create a database.
You can read about saving data in android here:
developer.android.com/intl/en/training/basics/data...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question