You will need a Adapter to manage Listview content.
Example:
Create Adapter. I suggest you read the documentation to better understand the responsibility of each method.
public class SeuAdapter extends BaseAdapter {
List<String> lista = new ArrayList<>();
Context context;
public SeuAdapter(Context context, List<String> lista){
this.lista = lista;
this.context = context;
}
@Override
public int getCount() {
return lista.size();
}
@Override
public Object getItem(int position) {
return lista.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater layoutInflater = LayoutInflater.from(context);
View view = layoutInflater.inflate(R.layout.seu_layout, null);
//TODO preencher a view com as informações necessárias
return view;
}
}
Instantiate Adapter to use in listview:
SeuAdapter seuAdapter = new SeuAdapter(getContext(), lista);
ListView listView = (ListView) findViewById(R.id.listview);
listview.set(adapter)
Listener to take action when selecting an item from the list, using the Onitemclicklistener:
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//TODO pode utilizar a variavel position para pegar o objeto selecioando da lista.
}
});