0

正如您在下面看到的,我的底部导航器中有这个片段布局:

在此处输入图像描述

因此,当应用程序用户从回收视图中单击卡片项目时,我想在此搜索片段上打开另一个片段。我正在尝试这样做,但出现此错误:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: mobhair.com.br, PID: 538
    java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.support.v7.widget.RecyclerView$ViewHolder.shouldIgnore()' on a null object reference
    at android.support.v7.widget.RecyclerView.findMinMaxChildLayoutPositions(RecyclerView.java:4101)
    at android.support.v7.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:3835)

真不知道是哪个问题。你能帮帮我吗?

遵循我到目前为止所做的事情:

搜索片段:

public class SearchFragment extends Fragment {

    private SearchViewAdataper searchViewAdataper;
    private RecyclerView recyclerView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.search_screen_fragment, container, false);
        final ProgressDialog progressDialog = new ProgressDialog(view.getContext());

        Toolbar mToolbar = (Toolbar) view.findViewById(R.id.toolbar);
        mToolbar.setTitleTextColor(Color.WHITE);
        mToolbar.setTitle(R.string.title_search);

        progressDialog.setMessage(getString(R.string.loading_data));
        recyclerView = (RecyclerView) view.findViewById(R.id.search_recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(view.getContext(), LinearLayoutManager.VERTICAL, false));

        SearchManager searchManager = new SearchManager(view.getContext());
        searchManager.getAllProfessions(new SearchServiceListener() {
            @Override
            public void onSuccess(List<SearchDataModel> searchDataModels) {
                searchViewAdataper = new SearchViewAdataper(getContext(), searchDataModels);
                recyclerView.setAdapter(searchViewAdataper);
                progressDialog.dismiss();
            }

            @Override
            public void onFail(Throwable t) {
                progressDialog.dismiss();
                Toast.makeText(getContext(), R.string.communication_server_problem, Toast.LENGTH_LONG).show();
            }
        });

        return view;
    }
}

SearchSectionAdapter 适配器:在这里它管理所有卡片项和动作,从卡片项中单击侦听器以调用新片段

注意:我将只放 setOnClickListener 实现。如有必要,所有实施都让我知道,我可以更新这个问题。

holder.mSearchItemImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {

            ProfessionalManager professionalManager = new ProfessionalManager(v.getContext());
            professionalManager.getAllProfessionalByProfessionDescription(singleItem.getDescription(), new ProfessionalServiceListener() {
                @Override
                public void onSuccess(List<Professional> professionals) {
                    /*Intent intent = new Intent(v.getContext(), ProfessionalListActivity.class);
                    v.getContext().startActivity(intent);*/
                    Fragment fragment = new ProfessionalListFragment();
                    FragmentTransaction ft = ((FragmentActivity)context)
                            .getSupportFragmentManager()
                            .beginTransaction();
                    ft.replace(R.id.search_recyclerView, fragment);
                    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
                    ft.addToBackStack(null);
                    ft.commit();
                }

                @Override
                public void onFail(Throwable t) {

                }
            });
        }
    });
4

1 回答 1

0

你在这里使用 recyclerView 参考

recyclerView = (RecyclerView) view.findViewById(R.id.search_recyclerView);

再次使用 recyclerView 替换产生问题的片段

ft.replace(R.id.search_recyclerView, fragment);

你需要<fragment>布局来替换它。

于 2019-09-09T17:28:35.253 回答