I want to show a user dialog with a counter. Oddly enough, I get a NullPointerException when trying to install a spinner adapter ...
Dialog dialog = new Dialog(this.getApplicationContext()); dialog.setContentView(R.layout.dialog_spinner); ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, new String[] {"0","1","2"}); spin = (Spinner)dialog.findViewById(R.id.spinQ);
Xml layout code:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent" android:paddingLeft="10dip" > <Spinner android:id="@+id/spinQ" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
UPDATE:
AlertDialog alertDialog; LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.dialog_spinner, (ViewGroup) findViewById(R.id.root)); ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, new String[] {"0","1","2"}); spin = (Spinner) findViewById(R.id.spinQ);
source share