0

So far no luck. Been trying to add an object to my listview with no luck. After I add it should just out put the name of the assignment even though I set the object with other parameters such as grade and category. This is code is placed into a fragment java class that outputs the listview

private void populateListView(){
    TeamArrayList = new ArrayList<CourseWorkItem>();
    CourseWorkItem myItem = null;
    myItem.setName("First Assignment");
    myItem.setCategory("Homework");
    myItem.setGrade(60);

    TeamArrayList.add(myItem);

    //creates an adapter
    itemArrayAdapter = new ArrayAdapter<CourseWorkItem>(this,R.layout.individualview,TeamArrayList);
    ListView v = (ListView) findViewById(R.id.courseListXML);
    v.setAdapter(itemArrayAdapter);

}
Carlitos
  • 419
  • 4
  • 20

2 Answers2

1

Have you overriden the toString method of CourseWorkItem to display the name?

Abhinav Nair
  • 958
  • 1
  • 8
  • 29
0

you are using default array adapter then you should pass the value as String[] ,otherwise you should create a custom adapter for this

try this for default array adapter

String[] strings=new String[]{"First Assignment","Second Assignment"}; 
    //creates an adapter
    itemArrayAdapter = new ArrayAdapter<CourseWorkItem>(this,R.layout.individualview,TeamArrayList);
    ListView v = (ListView) findViewById(R.id.courseListXML);
    v.setAdapter(itemArrayAdapter);