I'm a beginner in Java / Android programming, and would like some help with adding items to a ListView.
The app receives the first 5 records of a Json (Url), and adds everything in the ListView so far.
The app then displays a button, which when clicked, searches the next 5 records.
Here's my question : The app replaces the first 5 records for the next 5, and I need this new content query added to the end of the ListView and not replace what was already.
Below, code snippets
Main Activity
// Populando Campeoes ListView
private void popularCampeoes() {
ArrayList<Campeoes> newCampeoes = Campeoes.fromJson(JsonCampeoes);
CampeoesAdapter adapterCampeoes = new CampeoesAdapter(this, newCampeoes);
ListView listClubeCampeoes = (ListView) findViewById(R.id.listClubeCampeoes);
listClubeCampeoes.setAdapter(adapterCampeoes);
}
With Json downloaded, the app invokes the popular methodCampeoes ();
ChampionsAdapter
class CampeoesAdapter extends ArrayAdapter<Campeoes> {
CampeoesAdapter(Context context, ArrayList<Campeoes> campeoes) {
super(context, 0, campeoes);
}
private Context context;
@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
final Campeoes campeoes = getItem(position);
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.campeoes_linha, parent, false);
}
TextView tvTitulo = (TextView) convertView.findViewById(R.id.clubeCampTitulo);
TextView tvConteudo = (TextView) convertView.findViewById(R.id.clubeCampConteudo);
assert campeoes != null;
tvTitulo.setText(campeoes.CampTitulo);
tvConteudo.setText(campeoes.CampConteudo);
return convertView;
}
}
I thank you immediately for any help you may have.