android.view.ContextThemeWrapper 不能投射到 android.app.Activity
2022-09-02 11:18:46
我不是设计师,但当我得到这个项目时,我不能专门打开一些屏幕,我认为它们是屏幕,我们只重用一些已经创建的布局。总之有人可以帮助我吗?@Override在BindViewHolder(@NonNull final ProductsAdapter.ViewHolder, final int position) { String imageUrl = ProductsList.get(position).getImage();
holder.itemName.setText(ProductsList.get(position).getName());
Picasso.with(context).load(imageUrl).into(holder.itemImage);
holder.parentLayot.setOnClickListener(new View.OnClickListener() {
public String currentActivity;
@Override
public void onClick(View v) {
Activity activity = (Activity) v.getContext();
activity.runOnUiThread(bd);
String activityName = activity.getClass().getSimpleName();
// Toast.makeText(activity,ProductsList.get(position).getId(),Toast.LENGTH_SHORT).show();
if (activityName.equals("Product_View")){
// Toast.makeText(activity,"Click and pass",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(activity, Second_Product_View.class);
intent.putExtra("item_name", ProductsList.get(position).getName());
intent.putExtra("item_id", ProductsList.get(position).getId());
intent.putExtra("item_category_name", ProductsList.get(position).getName());
intent.putExtra("item_category_id", ProductsList.get(position).getId());
activity.startActivity(intent);
} else if(activityName.equals("Second_Product_View")){
Intent intent = new Intent(activity, Third_Product_View.class);
intent.putExtra("item_category_name", activity.getIntent().getStringExtra("item_category_name"));
intent.putExtra("item_category_id", activity.getIntent().getStringExtra("item_category_id"));
intent.putExtra("item_subcategory_name", ProductsList.get(position).getName());
intent.putExtra("item_subcategory_id", ProductsList.get(position).getId());
intent.putExtra("item_name", ProductsList.get(position).getName());
intent.putExtra("item_id", ProductsList.get(position).getId());
activity.startActivity(intent);
} else if(activityName.equals("Third_Product_View")){
Intent intent = new Intent(activity, Fourth_Product_View.class);
intent.putExtra("item_category_name", activity.getIntent().getStringExtra("item_category_name"));
intent.putExtra("item_category_id", activity.getIntent().getStringExtra("item_category_id"));
intent.putExtra("item_subcategory_name", activity.getIntent().getStringExtra("item_subcategory_name"));
intent.putExtra("item_subcategory_id", activity.getIntent().getStringExtra("item_subcategory_id"));
intent.putExtra("item_section_name", ProductsList.get(position).getName());
intent.putExtra("item_section_id", ProductsList.get(position).getId());
intent.putExtra("item_name", ProductsList.get(position).getName());
intent.putExtra("item_id", ProductsList.get(position).getId());
activity.startActivity(intent);
} else if(activityName.equals("Fourth_Product_View")){
holder.downloadManager = (DownloadManager)activity.getSystemService(Context.DOWNLOAD_SERVICE);
String file = activity.getString(R.string.base_url) + "files/example-" + ProductsList.get(position).getId() + ".pdf";
Uri uri = Uri.parse(file);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
Long reference = holder.downloadManager.enqueue(request);
} else if (activityName.equals("Formation_View")){
Intent intent = new Intent(activity, Second_Formation_View.class);
intent.putExtra("item_name", ProductsList.get(position).getName());
intent.putExtra("item_id", ProductsList.get(position).getId());
intent.putExtra("item_category_name", ProductsList.get(position).getName());
intent.putExtra("item_category_id", ProductsList.get(position).getId());
activity.startActivity(intent);
} else if(activityName.equals("Second_Formation_View")){
Intent intent = new Intent(activity, Third_Formation_View.class);
intent.putExtra("item_category_name", activity.getIntent().getStringExtra("item_category_name"));
intent.putExtra("item_category_id", activity.getIntent().getStringExtra("item_category_id"));
intent.putExtra("item_subcategory_name", ProductsList.get(position).getName());
intent.putExtra("item_subcategory_id", ProductsList.get(position).getId());
intent.putExtra("item_name", ProductsList.get(position).getName());
intent.putExtra("item_id", ProductsList.get(position).getId());
activity.startActivity(intent);
} else if(activityName.equals("Third_Formation_View")){
holder.downloadManager = (DownloadManager)activity.getSystemService(Context.DOWNLOAD_SERVICE);
String file = activity.getString(R.string.base_url) + "files/example-" + ProductsList.get(position).getId() + ".pdf";
Uri uri = Uri.parse(file);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
Long reference = holder.downloadManager.enqueue(request);
} else if (activityName.equals("Tools_View")){
Intent intent = new Intent(activity, Second_Tools_View.class);
intent.putExtra("item_name", ProductsList.get(position).getName());
intent.putExtra("item_id", ProductsList.get(position).getId());
intent.putExtra("item_category_name", ProductsList.get(position).getName());
intent.putExtra("item_category_id", ProductsList.get(position).getId());
activity.startActivity(intent);
} else if(activityName.equals("Second_Tools_View")){
holder.downloadManager = (DownloadManager)activity.getSystemService(Context.DOWNLOAD_SERVICE);
String file = activity.getString(R.string.base_url) + "files/example-" + ProductsList.get(position).getId() + ".pdf";
Uri uri = Uri.parse(file);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
Long reference = holder.downloadManager.enqueue(request);
}
}
});
}
和 logcat 显示这个
java.lang.ClassCastException: android.view.ContextThemeWrapper cannot be cast to android.app.Activity
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24701)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at