Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I print list of objects in android

I am using this code to show missed calls in my application while I am using Call class to define an object each time then store it in test how Can I print all objects in test list in my application?

 List<Call> callList = new ArrayList<Call>();
        while (c.moveToNext()) {
            Call call = new Call();
            call.setNumber(c.getString(c.getColumnIndex(CallLog.Calls.NUMBER)));
           /* if (c.getInt(c.getColumnIndex(CallLog.Calls.TYPE)) == CallLog.Calls.OUTGOING_TYPE) {
                call.setOut(true);
            } else {
                call.setOut(false);
            }*/

            call.setName(c.getString(c.getColumnIndex(CallLog.Calls.CACHED_NAME)));
            call.setTime(c.getLong(c.getColumnIndex(CallLog.Calls.DATE)));
            call.setDuration(c.getLong(c.getColumnIndex(CallLog.Calls.DURATION)));

            if ( c.getString(c.getColumnIndex(CallLog.Calls.CACHED_NAME))!= null) 
            {
                continue;
            }

            callList.add(call);
        }
        c.close();
        }
like image 792
user3498298 Avatar asked Mar 21 '23 00:03

user3498298


2 Answers

you can override toString() method on Call class like:

    @Override
    public String toString() {

        return Name+" "+Time+" "+Duration;
    }

and print your list in for statement like:

for (int i = 0 ; i < callList.size() ; i++)
    Log.d("value is" , callList.get(i).toString()); 
like image 180
Shayan Pourvatan Avatar answered Mar 28 '23 10:03

Shayan Pourvatan


You can just iterate through the list and print the elements :

List<Call> callList = new ArrayList<Call>();
     for(Call call : callList){
        System.out.print("Name - " +call.getName() +
        "Number - "+call.getNumber() +
        "Time - "+call.getTime() +
        "Duration - "call.getDuration());
     }
like image 32
kAnNaN Avatar answered Mar 28 '23 09:03

kAnNaN