0

我正在基于改造回发数据的回收器列表视图中显示一些数据。它正在工作,现在我正在尝试在 Listview ItemClick 上显示底部工作表对话框。为此,我onBindViewHolderDataAdapter课堂上实现了项目单击事件。下面是我的代码DataAdapter.java

public class DataAdapter extends RecyclerView.Adapter<DataAdapter.MyViewHolder>{

private Context context;
private List<Datum> dataList;

public DataAdapter(Context context, List<Datum> dataList) {
    this.context = context;
    this.dataList = dataList;
}

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_movie2,parent,false);
    return new MyViewHolder(view);
}


@Override
public void onBindViewHolder(final MyViewHolder holder, final int position) {
    holder.tvtitle.setText(dataList.get(position).getCar_name());
    holder.tvFare.setText(dataList.get(position).getTotal_fare());
    holder.tvBreakdown.setText("Base Fare "+dataList.get(position).getBase_fare()+dataList.get(position).getPer_km());
    holder.tvCount.setText(dataList.get(position).getCount());

    Picasso.with(context)
            .load(dataList.get(position).getUrl())
            .placeholder(R.drawable.user)
            .error(R.drawable.user)
            .into(holder.list_image);

    holder.itemView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {

        //Toast.makeText(context, dataList.get(position).getTotal_fare(), Toast.LENGTH_SHORT).show();

        /***bottom sheet ********************************************************/


        final BottomSheetDialog dialog3 = new BottomSheetDialog((Activity)context);
        dialog3.setContentView(R.layout.hire_now);

        final TextView tvMainFare = (TextView) dialog3.findViewById(R.id.tvMainFare);
        final TextView tvRegularFare = (TextView) dialog3.findViewById(R.id.tvRegularFare);
        final Button btn_hire_now = (Button) dialog3.findViewById(R.id.btn_hire_now);

        final TextView tvDriver = (TextView) dialog3.findViewById(R.id.tvDriver);
        final TextView tvKMaway = (TextView) dialog3.findViewById(R.id.tvKMaway);

        final TextView tvDelete = (TextView) dialog3.findViewById(R.id.tvDelete);
        final TextView tvReport = (TextView) dialog3.findViewById(R.id.tvReport);
        final TextView tvPosition = (TextView) dialog3.findViewById(R.id.tvPosition);
        dialog3.show();

       }
    });

}

在项目点击它给出以下错误

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.lorry9.rides, PID: 13121
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
    at android.view.ViewRootImpl.setView(ViewRootImpl.java:540)
    at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:259)
    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
    at android.app.Dialog.show(Dialog.java:286)
    at com.lorry9.rides.DataAdapter$1.onClick(DataAdapter.java:79)
    at android.view.View.performClick(View.java:4438)
    at android.view.View$PerformClick.run(View.java:18422)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5017)
    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:779)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    at dalvik.system.NativeStart.main(Native Method)
    I/Process: Sending signal. PID: 13121 SIG: 9
    Process 13121 terminated.

但是,当我在项目单击时吐司消息时,它正在工作,但没有显示底部的工作表对话框。我该如何解决这个问题,请帮忙

在我的活动中,我在改造回调中调用数据适配器

Call<List<Datum>> call= requestInterface.getTopRatedMovies(data);
    call.enqueue(new Callback<List<Datum>>() {
        @Override
        public void onResponse(Call<List<Datum>> call, Response<List<Datum>> response) {
            dataArrayList = response.body();
            Log.e(TAG, "onResponse: "+dataArrayList );
            dataAdapter=new DataAdapter(getApplicationContext(),dataArrayList);
            recyclerView.setAdapter(dataAdapter);
        }

        @Override
        public void onFailure(Call<List<Datum>> call, Throwable t) {
            Log.e("Error",t.getMessage());
        }

    });
4

0 回答 0