Ho un frammento in cui ho bisogno di mostrare una finestra di dialogo personalizzata.La funzionalità della finestra deve essere richiesta prima di aggiungere il contenuto mentre si implementa la finestra di dialogo in frammento
Si prega di controllare il mio codice qui sotto.
public class MyFragment extends Fragment{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.send_layout, container, false);
TextView txtView = (TextView) rootView.findViewById(R.id.tv);
txtView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openDialog();
}
});
return rootView;
}
public void openDialog(){
AppCompatDialog dialog = new AppCompatDialog(getContext(), R.style.package_types__dialog);
dialog.setContentView(R.layout.package_types_dialog);
dialog.show();
}
}
Quando si rimuove la linea:
dialog.setContentView(R.layout.package_types_dialog);
non v'è alcun errore, ma se uso lo stesso il seguente errore sta gettando:
FATAL EXCEPTION: main
10-20 19:42:57.489 23866-23866/in.edelworks.pickedup E/AndroidRuntime: Process: in.edelworks.pickedup, PID: 23866
10-20 19:42:57.489 23866-23866/in.edelworks.pickedup E/AndroidRuntime: android.util.AndroidRuntimeException: Window feature must be requested before adding content
10-20 19:42:57.489 23866-23866/in.edelworks.pickedup E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.throwFeatureRequestIfSubDecorInstalled(AppCompatDelegateImplV7.java:1584)
10-20 19:42:57.489 23866-23866/in.edelworks.pickedup E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.requestWindowFeature(AppCompatDelegateImplV7.java:509)
10-20 19:42:57.489 23866-23866/in.edelworks.pickedup E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:117)
10-20 19:42:57.489 23866-23866/in.edelworks.pickedup E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:148)
10-20 19:42:57.489 23866-23866/in.edelworks.pickedup E/AndroidRuntime: at android.support.v7.app.AppCompatDialog.onCreate(AppCompatDialog.java:60)
10-20 19:42:57.489 23866-23866/in.edelworks.pickedup E/AndroidRuntime: at android.app.Dialog.dispatchOnCreate(Dialog.java:361)
10-20 19:42:57.489 23866-23866/in.edelworks.pickedup E/AndroidRuntime: at android.app.Dialog.show(Dialog.java:262)
provare impostando l'ascoltatore onClick in –
aggiornamento OnStart la versione AppCompat a v22.1.0 – MKJParekh