0

在启动时,我的应用程序会启动一个片段,该片段显示“项目”的列表视图。当我点击一个项目时,会启动一个显示项目详细信息的新片段,包括另一个“任务”列表视图(每个项目对象可以包含许多任务)。

我在为第二个列表视图初始化 arrayadapter 时遇到问题。 tasksAdapter = new TasksArrayAdapter(getActivity(),selectedProject.getTasks());

它不会编译,Android Studios 提供以下原因:

incompatible types. Required: ProjectsArrayAdapter. Found: TasksArrayAdapter

ProjectsArrayAdapter 是在前一个片段上设置的,如下所示:

    //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();
        }
    });

为什么我不能创建这个新的阵列适配器?

4

1 回答 1

0

这是因为 tasksAdapter 被声明为 ProjectsArrayAdapter 而不是 TasksArrayAdapter - 复制/粘贴错误。

static TasksArrayAdapter tasksAdapter;

于 2015-06-09T12:49:39.233 回答