trolley

For this, you create a separate xml file (in the good folder, do new file, blank …) in which you create the wanted item, and you manage it in the java file:

 

List<ReceivedLog> logs = new ArrayList();
ListView logsListView;

 

private void populateList() {
    ArrayAdapter<ReceivedLog> adapter = new logListAdapter();
    logsListView.setAdapter(adapter);
}

private void addLog(InetAddress ip, Date date, String log){
    logs.add(new ReceivedLog(ip, date, log));
}

private class logListAdapter extends ArrayAdapter{
    public logListAdapter() {
        super(MainActivity.this, R.layout.log_item, logs);
    }

    @Override
    public View getView(int position, View view, ViewGroup parent){
        if (view == null)
            view = getLayoutInflater().inflate(R.layout.log_item, parent, false);
        ReceivedLog currentLog = logs.get(position);

        TextView ip = (TextView) view.findViewById(R.id.textIp);
        ip.setText(currentLog.getIp().toString());
        TextView date = (TextView) view.findViewById(R.id.textDate);
        date.setText(currentLog.getDate().toString());
        TextView log = (TextView) view.findViewById(R.id.textLogContent);
        log.setText(currentLog.getContent());

        return view;
    }
}

 

Back Next

Create android item list
Tagged on:         

2 thoughts on “Create android item list

Leave a Reply