[英]How to Delete message using AlertDialogBox from api response in Adapter class
[英]Custom AlertDialogBox does not show from different class
我的對話框有一個自定義布局,它顯示了我的應用程序中商店的可用產品:
popstoreproduct.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/backgroundgrey">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_marginVertical="20dp">
<TextView
android:id="@+id/txtlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="P R O D U C T"
android:textSize="16dp"
android:textStyle="bold"
android:layout_marginRight="15dp"
android:layout_marginLeft="20dp"
android:textColor="@color/text1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="L I S T"
android:textSize="16dp"
android:textColor="@color/text1"/>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/poprecycler"
android:layout_width="match_parent"
android:layout_height="500dp"
android:layout_gravity="center_horizontal"
android:overScrollMode="never"
android:layout_marginBottom="10dp"/>
</LinearLayout>
我必須在不同的活動中將此布局用作對話框,因此我創建了一個具有從 MainActivity 調用對話框的函數的類
實用程序.java
public class Utility {
public Utility() {
}
public void popStoreProduct(Context context,ArrayList<Stock> mainlist,ArrayList<Stock> menuList){
final AlertDialog.Builder mBuild = new AlertDialog.Builder(context,R.style.DialogSlideAnim);
LayoutInflater inflater = LayoutInflater.from(context);
View layout = inflater.inflate(R.layout.popstoreproduct,null);
final RecyclerView precycler =(RecyclerView)layout.findViewById(R.id.poprecycler);
LinearLayoutManager playoutManager = new LinearLayoutManager(context);
precycler.setLayoutManager(playoutManager);
precycler.setHasFixedSize(true);
AdapterPopStoreProduct pAdapter = new AdapterPopStoreProduct(context,mainlist,menuList);
precycler.setAdapter(pAdapter);
mBuild.setView(layout);
final AlertDialog dialog = mBuild.create();
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().getAttributes().gravity = Gravity.BOTTOM |Gravity.CLIP_HORIZONTAL;
dialog.show();
}
}
當我運行應用程序並在我的主要活動中調用該函數時,它崩潰並給出以下指向 dialog.show() 行的錯誤:
java.lang.IllegalStateException:您需要在此活動中使用 Theme.AppCompat 主題(或后代)。 在 com.example.myapp.Classes.Utility.popStoreProduct(Utility.java:288)
我不明白代碼有什么問題。 請幫助 PS:我在我的對話框中使用了從底部滑動的幻燈片動畫。
顯示您的styles
文件和Activity
的清單聲明。 因為錯誤說您的Activity
樣式必須是/擴展Theme.AppCompat
。 例如:
android:theme="@style/Theme.AppCompat.Light"
您還可以為所有將上述行添加到<application
標記而不是每個Activity
聲明的活動設置此主題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.