0

On startup, my app launches a fragment which displays a listView of 'projects'. When I click on a project, a new fragment is launched which displays the project's details, including another listView of 'tasks' (each project object can contain many tasks).

I am having trouble initializing the arrayadapter for the second listview. tasksAdapter = new TasksArrayAdapter(getActivity(),selectedProject.getTasks());

It wont compile, and Android Studios offers the following reason:

incompatible types. Required: ProjectsArrayAdapter. Found: TasksArrayAdapter

the ProjectsArrayAdapter was set up on the previous fragment like so:

    //initialize a custom ArrayAdapter to connect the object to the listView

    projectsAdapter = new ProjectsArrayAdapter(getActivity(), Projects.getInstance().getProjects());
    projectsList = (ListView) view.findViewById(R.id.listViewProjects);

    projectsList.setAdapter(projectsAdapter);

    //=========================================================================================
    //when you click on a project from the list
    //=========================================================================================

    //create onClickListener for listView items and launch project details fragment on click

    projectsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            FragmentProject myProject = new FragmentProject();

            //grab the object you clicked on
            Bundle args = new Bundle();
            args.putInt("ARG_POSITION", position);
            myProject.setArguments(args);

            //launch project details fragment
            FragmentManager manager = getFragmentManager();
            FragmentTransaction transaction = manager.beginTransaction();
            transaction.add(R.id.main_layout, myProject);
            transaction.commit();
        }
    });

Why cant I create this new array adapter?

TheGallows
  • 25
  • 6
  • This one is still stumping me. I'm quite sure the second parameter (the arraylist) is not the issue. I think it has something to do with the context already being used by the projects arrayadapter. – TheGallows Jun 07 '15 at 12:10
  • Is it the case that each activity can only have one ListView (or one list view adapter)? Perhaps I wont have this problem if I use a Child Fragment. In that case: Fragment with list of projects is populated. The user clicks on a project, and a child fragment showing project details and a listView of tasks is launched. – TheGallows Jun 08 '15 at 12:45
  • The following post suggests that what I'm trying to do is possible, although I would rather use a new fragment than a new activity since it will be more flexible across devices. http://stackoverflow.com/questions/4575132/displaying-a-new-list-after-selecting-an-item-from-a-listview-in-android – TheGallows Jun 08 '15 at 13:43
  • The fact that this doesnt seem to be a problem to anyone else suggests that I must have just made a silly mistake somewhere, but I cant see any such thing. – TheGallows Jun 09 '15 at 12:30

1 Answers1

0

It was because tasksAdapter was declared as a ProjectsArrayAdapter instead of a TasksArrayAdapter- a copy/paste error.

static TasksArrayAdapter tasksAdapter;

TheGallows
  • 25
  • 6