2012-10-21 79 views
1

我在Alertdialog中使用3个微调器。而我使用的纺纱无onitemselectedlistener它正确地填充,当我使用onItemSelectedListener它不是填充值,我试图从stackoverflow Questions其他一些建议,现在它的人口第一次当我点击一些项目中的所有值将会消失微调器不能正常工作

我发布我这里alertdialog代码

AlertDialog.Builder myDialog = new AlertDialog.Builder(CameraDemo.this); 
    myDialog.setTitle("Save"); 
    TableRow.LayoutParams rowparams = new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); 

    LinearLayout layout1 = new LinearLayout(CameraDemo.this); 
    layout1.setOrientation(LinearLayout.VERTICAL); 
    Spinner spin = new Spinner(CameraDemo.this); 
    Cursor cursor = placeData.queueAllDoc(); 
    startManagingCursor(cursor); 
    SimpleCursorAdapter cu = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, cursor, new String[]{SQLiteoperations.DOC_TYPE}, new int[]{android.R.id.text1}); 
    cu.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
    spin.setAdapter(cu); 

    spin.setOnItemSelectedListener(new OnItemSelectedListener() { 
     public void onItemSelected(AdapterView<?> parent, View view, int position, 
       long id) { 
      if(mSpinnerInitializedCount < mSpinnerCount){ 
       mSpinnerInitializedCount++; 
       return;       
      } 
      Cursor incursor1 = (Cursor) parent.getItemAtPosition(position); 
      int did = incursor1.getInt(incursor1.getColumnIndex(SQLiteoperations.DOC_ID)); 
      doc_id = did; 
      System.out.println(did); 
      incursor1.close(); 
     } 
     public void onNothingSelected(AdapterView<?> arg0) { 
     return; 
     } 
    }); 

    LayoutParams TxtLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 

    final EditText saveEdt = new EditText(CameraDemo.this); 
    LayoutParams locationEdtLayoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); 
    saveEdt.setLayoutParams(locationEdtLayoutParams); 

    final TextView saveTxt = new TextView(CameraDemo.this); 
    saveTxt.setLayoutParams(TxtLayoutParams); 
    saveTxt.setText("Name"); 
    TextView groupTxt = new TextView(CameraDemo.this); 
    groupTxt.setLayoutParams(TxtLayoutParams); 
    groupTxt.setText("Group"); 
    TextView clientTxt = new TextView(CameraDemo.this); 
    clientTxt.setLayoutParams(TxtLayoutParams); 
    clientTxt.setText("Client"); 
    TextView docTxt = new TextView(CameraDemo.this); 
    docTxt.setLayoutParams(TxtLayoutParams); 
    docTxt.setText("Document Type"); 

    TableRow grouprow = new TableRow(CameraDemo.this); 
    grouprow.setLayoutParams(rowparams); 
    final TableRow clientrow = new TableRow(CameraDemo.this); 
    clientrow.setLayoutParams(rowparams); 
    final TableRow docrow = new TableRow(CameraDemo.this); 
    docrow.setLayoutParams(rowparams); 
    final TableRow namerow = new TableRow(CameraDemo.this); 
    namerow.setLayoutParams(rowparams); 



    Spinner spin2 = new Spinner(CameraDemo.this); 
    Cursor cursor2 = placeData.queueAllGroup(); 
    startManagingCursor(cursor2); 
    SimpleCursorAdapter cu2 = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, cursor2, new String[]{SQLiteoperations.GROUP_NAME}, new int[]{android.R.id.text1}); 
    cu2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
    spin2.setAdapter(cu2); 

    spin2.setOnItemSelectedListener(new OnItemSelectedListener() { 
     public void onItemSelected(AdapterView<?> parent, View view, int position, 
       long id) { 
      if(mSpinnerInitializedCount < mSpinnerCount){ 
       mSpinnerInitializedCount++; 
       return;       
      } 
      Cursor incursor2 = (Cursor) parent.getItemAtPosition(position); 
      int gid = incursor2.getInt(incursor2.getColumnIndex(SQLiteoperations.GROUP_ID)); 
      group_id = gid; 
      System.out.println(gid); 
      incursor2.close(); 
     } 
     public void onNothingSelected(AdapterView<?> arg0) { 
      return; 
     } 
    }); 

    Spinner spin3 = new Spinner(CameraDemo.this); 
    Cursor cursor3 = placeData.queueAllClient(1); 
    startManagingCursor(cursor3); 
    SimpleCursorAdapter cu3 = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, cursor3, new String[]{SQLiteoperations.CLIENT_NAME}, new int[]{android.R.id.text1}); 
    cu3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
    spin3.setAdapter(cu3); 

    spin3.setOnItemSelectedListener(new OnItemSelectedListener() { 
     public void onItemSelected(AdapterView<?> parent, View view, int position, 
       long id) { 
      if(mSpinnerInitializedCount < mSpinnerCount){ 
       mSpinnerInitializedCount++; 
       return;       
      } 
      Cursor incursor3 = (Cursor) parent.getItemAtPosition(position); 
      int cid = incursor3.getInt(incursor3.getColumnIndex(SQLiteoperations.CLIENT_ID)); 
      client_id = cid; 
      System.out.println(cid); 
      incursor3.close(); 
     } 
     public void onNothingSelected(AdapterView<?> arg0) { 
      return; 
     } 
    }); 

    grouprow.addView(groupTxt); 
    grouprow.addView(spin2); 
    clientrow.addView(clientTxt); 
    clientrow.addView(spin3); 
    docrow.addView(docTxt); 
    docrow.addView(spin); 
    namerow.addView(saveTxt); 
    namerow.addView(saveEdt); 

    layout1.addView(grouprow); 
    layout1.addView(clientrow); 
    layout1.addView(docrow); 
    layout1.addView(namerow); 

    myDialog.setView(layout1); 
    myDialog.show(); 

请帮我找到了问题

回答

0

我不认为你应该关闭它通过调用

得到光标

你不查询任何东西。它已由活动

+0

管理明确告诉我必须做什么? – ponraj

+0

删除所有cursor.closE调用 – nandeesh

+0

雅它工作:)谢谢 – ponraj