Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom number picker inside fragment
    text
    copied!<p>Please, help me with using <code>NumberPicker</code> from <a href="https://github.com/SimonVT/android-numberpicker" rel="nofollow">https://github.com/SimonVT/android-numberpicker</a>. I have fragment inside which I have button. After clicking button I want to show my number picker (as a pop-up, not new screen). So what I did: I created <code>NumberPickerCustomDialog</code></p> <pre><code>public class NumberPickerCustomDialog extends DialogFragment { Context context; @Override public Dialog onCreateDialog(Bundle savedInstanceState) { // get context context = getActivity().getApplicationContext(); // make dialog object AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // get the layout inflater LayoutInflater li = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); // inflate our custom layout for the dialog to a View View view = li.inflate(R.layout.activity_dark, null); // inform the dialog it has a custom View builder.setView(view); // and if you need to call some method of the class NumberPicker np = (NumberPicker) view .findViewById(R.id.numberPicker); // create the dialog from the builder then show return builder.create(); } </code></pre> <p>}</p> <p>And now in my fragment, after clicking the button I try to show my number picker:</p> <pre><code>FragmentManager fm = getFragmentManager(); NumberPickerCustomDialog yourDialog = new NumberPickerCustomDialog(); yourDialog.show(fm, "some_optional_tag"); </code></pre> <p>My layout looks:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:gravity="center"&gt; &lt;net.simonvt.numberpicker.NumberPicker android:id="@+id/numberPicker" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; </code></pre> <p></p> <p>I included library into project, copied layouts and got error:</p> <pre><code>04-17 11:33:28.264: E/AndroidRuntime(10891): FATAL EXCEPTION: main 04-17 11:33:28.264: E/AndroidRuntime(10891): android.view.InflateException: Binary XML file line #8: Error inflating class net.simonvt.numberpicker.NumberPicker 04-17 11:33:28.264: E/AndroidRuntime(10891): at android.view.LayoutInflater.createView(LayoutInflater.java:613) 04-17 11:33:28.264: E/AndroidRuntime(10891): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687) 04-17 11:33:28.264: E/AndroidRuntime(10891): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 04-17 11:33:28.264: E/AndroidRuntime(10891): at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 04-17 11:33:28.264: E/AndroidRuntime(10891): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 04-17 11:33:28.264: E/AndroidRuntime(10891): at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 04-17 11:33:28.264: E/AndroidRuntime(10891): at pl.package.jp.Me.NumberPickerCustomDialog.onCreateDialog(NumberPickerCustomDialog.java:26) 04-17 11:33:28.264: E/AndroidRuntime(10891): at android.support.v4.app.DialogFragment.getLayoutInflater(DialogFragment.java:295) 04-17 11:33:28.264: E/AndroidRuntime(10891): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911) 04-17 11:33:28.264: E/AndroidRuntime(10891): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088) 04-17 11:33:28.264: E/AndroidRuntime(10891): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682) 04-17 11:33:28.264: E/AndroidRuntime(10891): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444) 04-17 11:33:28.264: E/AndroidRuntime(10891): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:429) </code></pre> <p>What am I doing wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload