Android - how to replace the fragment when compressing eel. in BottomSheetDialog



  • How do you get the meaning and update the fragment? I wanted to solve this as a routine replacement, but there's a problem. I do, but I make a mistake:

    public class BottomSheetDialogView {
    
        static final String[] sStringList = new String[] {
                "dru", "mto", "3", "4"};
    
        public BottomSheetDialogView(Context context) {
            BottomSheetDialog dialog = new BottomSheetDialog(context);
    
            View view = LayoutInflater.from(context).inflate(R.layout.numb_dialog, null);
    
    
            RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.bottom_sheet_recycler_view);
            recyclerView.setLayoutManager(new GridLayoutManager((context), 1));
    
            recyclerView.setAdapter(new SimpleAdapter());
    
            dialog.setContentView(view);
            dialog.show();        
        }
    
    
        public static void show(Context context) {
            new BottomSheetDialogView(context);
        }
    
    
        private static class ViewHolder extends RecyclerView.ViewHolder {
    
            private String mBoundString;
            private TextView mTextView;
            private  View mView;
    
            public ViewHolder(View itemView) {
                super(itemView);
    
                mView = itemView;
                mTextView = (TextView) itemView.findViewById(R.id.numb);
            }
        }
    
    
        private static class SimpleAdapter extends RecyclerView.Adapter<ViewHolder> {
    
    
            @Override
            public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                LayoutInflater inflater = LayoutInflater.from(parent.getContext());
                View view = inflater.inflate(R.layout.numb_item, null);
                return new ViewHolder(view);
            }
    
    
            @Override
            public void onBindViewHolder(final ViewHolder holder, int position) {
                holder.mTextView.setText(sStringList[position]);
                holder.mBoundString = sStringList[position];
    
    
                holder.mTextView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Context context = view.getContext();
                        SettingsFragment news = new SettingsFragment();
                        FragmentManager fragmentManager = ((StartActivity)context).getFragmentManager();
                        fragmentManager.beginTransaction().replace(R.id.frame_container,  news).commit();
                    }
                });
            }
    
    
            @Override
            public int getItemCount() {
                return sStringList.length;
    
            }        
      }
    

    }

    Writing a mistake:

    Process: ru.667.566, PID: 14174
    java.lang.ClassCastException: android.support.v7.widget.TintContextWrapper cannot be cast to ru.667.566.StartActivity
    at ru.amon.hellonhmt.Dialog.NumbSheetDialogView$SimpleAdapter$1.onClick(NumbSheetDialogView.java:146)
    at android.view.View.performClick(View.java:4626)
    at android.view.View$PerformClick.run(View.java:19293)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:157)
    at android.app.ActivityThread.main(ActivityThread.java:5293)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
    at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:136)
    at dalvik.system.NativeStart.main(Native Method)



  • Updated code:

    public class BottomSheetDialogView {
    
    static final String[] sStringList = new String[] {
            "dru", "mto", "3", "4"};
    
    private View.OnClickListener clickListener;
    
    public BottomSheetDialogView(Context context, View.OnClickListener clickListener) {
        this.clickListener = clickListener;
        BottomSheetDialog dialog = new BottomSheetDialog(context);
    
        View view = LayoutInflater.from(context).inflate(R.layout.numb_dialog, null);
    
    
        RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.bottom_sheet_recycler_view);
        recyclerView.setLayoutManager(new GridLayoutManager((context), 1));
    
        recyclerView.setAdapter(new SimpleAdapter());
    
    
    
        dialog.setContentView(view);
        dialog.show();
    
    }
    
    
    public static void show(Context context) {
        new BottomSheetDialogView(context);
    }
    
    
    private class ViewHolder extends RecyclerView.ViewHolder {
    
        private String mBoundString;
        private TextView mTextView;
        private  View mView;
    
        public ViewHolder(View itemView) {
            super(itemView);
    
            mView = itemView;
            mTextView = (TextView) itemView.findViewById(R.id.numb);
        }
    }
    
    
    private static class SimpleAdapter extends RecyclerView.Adapter<ViewHolder> {
    
    
        @Override
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            LayoutInflater inflater = LayoutInflater.from(parent.getContext());
            View view = inflater.inflate(R.layout.numb_item, null);
            return new ViewHolder(view);
        }
    
    
        @Override
        public void onBindViewHolder(final ViewHolder holder, int position) {
            holder.mTextView.setText(sStringList[position]);
            holder.mBoundString = sStringList[position];
    
            holder.mTextView.setOnClickListener(clickListener);
        }
    
        @Override
        public int getItemCount() {
            return sStringList.length;
    
        }
    
    }
    

    }

    And create a dialogue in a fragment, as appropriate:

    new BottomSheetDialogView(getContext(), new View.OnClickListener() {
    @Override
    public void onClick(View view) {
    SettingsFragment news = new SettingsFragment();
    FragmentManager fragmentManager = getActivity().getFragmentManager();
    fragmentManager.beginTransaction()
    .replace(R.id.frame_container, news)
    .commit();
    }
    });




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2