警报对话框中的微调器

时间:2012-04-03 15:09:58

标签: android android-alertdialog android-spinner

你能帮帮我吗?

public void getCategory() {

    AlertDialog alertDialog;


    LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.spinner_alert, lV_new_spesa);

    //Apriamo il db creato tramite MissioniDb a cui passo il contesto della classe attuale ovvero Lista_Missioni
    SpinnerDb sdb=new SpinnerDb(getApplicationContext());

    //apriamo il db
    sdb.open();  

    //Chiamo la Query che in questo caso è un all
    c=sdb.fetchSPINNER();

    startManagingCursor(c);

    // create an array to specify which fields we want to display
    String[] from = new String[]{SpinnerDb.SpinnerMetaData.SPINNER_CAT_KEY};

    // create an array of the display item we want to bind our data to
    int[] to = new int[]{android.R.id.text1};

    // create simple cursor adapter
    SimpleCursorAdapter spadapter =
      new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, c, from, to );
    spadapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );

    stopManagingCursor(c);
    //Chiudo il db perchè ho finito di riempire la mia list view
    sdb.close();


    Spinner spin = (Spinner) layout.findViewById(R.id.spinQ);
    //I get the error in the following line:
    spin.setAdapter(spadapter);

    //Definisco cosa deve fare quando un elemento di tale spinner viene premuto
    spin.setOnItemSelectedListener(new SpinnerItemSelectedListener());

    Builder builder = new AlertDialog.Builder(this);
    builder.setView(layout);
    alertDialog = builder.create();
    alertDialog.show();

///////////////////

   04-03 15:08:10.852: E/AndroidRuntime(910): FATAL EXCEPTION: main
    04-03 15:08:10.852: E/AndroidRuntime(910): java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView
    04-03 15:08:10.852: E/AndroidRuntime(910):  at android.widget.AdapterView.addView(AdapterView.java:461)
    04-03 15:08:10.852: E/AndroidRuntime(910):  at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
    04-03 15:08:10.852: E/AndroidRuntime(910):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
    04-03 15:08:10.852: E/AndroidRuntime(910):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
    04-03 15:08:10.852: E/AndroidRuntime(910):  at spese.gestore.androidiani.Nuova_Spesa_2.getCategory(Nuova_Spesa_2.java:412)
    04-03 15:08:10.852: E/AndroidRuntime(910):  at spese.gestore.androidiani.Nuova_Spesa_2.onCreateDialog(Nuova_Spesa_2.java:215)
    04-03 15:08:10.852: E/AndroidRuntime(910):  at android.app.Activity.onCreateDialog(Activity.java:2472)
    04-03 15:08:10.852: E/AndroidRuntime(910):  at android.app.Activity.createDialog(Activity.java:881)
    04-03 15:08:10.852: E/AndroidRuntime(910):  at android.app.Activity.showDialog(Activity.java:2547)
    04-03 15:08:10.852: E/AndroidRuntime(910):  at android.app.Activity.showDialog(Activity.java:2514)
    04-03 15:08:10.852: E/AndroidRuntime(910):  at spese.gestore.androidiani.Nuova_Spesa_2$2.onItemClick(Nuova_Spesa_2.java:123)
    04-03 15:08:10.852: E/AndroidRuntime(910):  at android.widget.AdapterView.performItemClick(AdapterView.java:284)
    04-03 15:08:10.852: E/AndroidRuntime(910):  at android.widget.ListView.performItemClick(ListView.java:3382)
    04-03 15:08:10.852: E/AndroidRuntime(910):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
    04-03 15:08:10.852: E/AndroidRuntime(910):  at android.os.Handler.handleCallback(Handler.java:587)
    04-03 15:08:10.852: E/AndroidRuntime(910):  at android.os.Handler.dispatchMessage(Handler.java:92)
    04-03 15:08:10.852: E/AndroidRuntime(910):  at android.os.Looper.loop(Looper.java:123)
    04-03 15:08:10.852: E/AndroidRuntime(910):  at android.app.ActivityThread.main(ActivityThread.java:4627)
    04-03 15:08:10.852: E/AndroidRuntime(910):  at java.lang.reflect.Method.invokeNative(Native Method)
    04-03 15:08:10.852: E/AndroidRuntime(910):  at java.lang.reflect.Method.invoke(Method.java:521)
    04-03 15:08:10.852: E/AndroidRuntime(910):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    04-03 15:08:10.852: E/AndroidRuntime(910):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    04-03 15:08:10.852: E/AndroidRuntime(910):  at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:-2)

04-03 15:08:10.852: E/AndroidRuntime(910):  at spese.gestore.androidiani.Nuova_Spesa_2.getCategory(Nuova_Spesa_2.java:412)
04-03 15:08:10.852: E/AndroidRuntime(910):  at spese.gestore.androidiani.Nuova_Spesa_2.onCreateDialog(Nuova_Spesa_2.java:215) 
04-03 15:08:10.852: E/AndroidRuntime(910):  at spese.gestore.androidiani.Nuova_Spesa_2$2.onItemClick(Nuova_Spesa_2.java:123)

阅读你的代码,这些代码是什么?