2012-04-04 8 views
1

문제가 있습니다. 내 활동에는 단추가 있고 단추를 클릭하면 메서드가 호출됩니다. 이 방법은 나에게 listview와 경고 대화 상자를 보여줍니다 그리고 나는 항목 클릭 변수에 저장하고 싶습니다 그리고 그 방법을 닫고 싶지만 닫지 않습니다! 왜?? 메소드의 코드를 게시합니다. 내 logcat이 나에게 어떤 오류도주지 않는다. 아무도 나를 도울 수 있습니까 ?? please경고 대화 상자가 닫히지 않습니다.

private void getValuta() { 

AlertDialog.Builder miaAlert = new AlertDialog.Builder(this); 

final ListView lV = new ListView(this); 

Cursor c = null; 

miaAlert.setTitle("Choose Valuta"); 

c = vdb.fetchValuteListView("0"); 

startManagingCursor(c); 


SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
     android.R.layout.simple_list_item_1, 
     c, 
     new String[] { 
       ValuteDb.ValuteMetaData.VALUTE_NAME_KEY}, 
     new int[] { android.R.id.text1}); 

stopManagingCursor(c); 

lV.setAdapter(adapter); 

miaAlert.setView(lV); 

miaAlert.setCancelable(false); 

lV.setOnItemClickListener(new OnItemClickListener() { 
    public void onItemClick(AdapterView<?> parent, View v, 
      int position, long id) { 

     String riga = String.valueOf(id); 
     String confr = vdb.getRecord(riga,2); 
     System.out.println("position= " + position + "/id= " + id+"/nome= "+confr); 
     new_valuta = vdb.getRecord(riga,2); 
     listdb.update("9", "Valuta", new_valuta, "2"); 
     c_list.requery(); 

     return; 

    } 
}); 

AlertDialog alert = miaAlert.create(); 

alert.show();} 
+4

중복 가능성을 기각하는 [방법 닫지 않습니다 (http://stackoverflow.com/questions/10011500/method-doesnt-close) – Luksprog

+0

하지 마십시오 중복 질문 게시. 아, 그리고 대화 상자를 닫으려는 것이지, 방법이 아니라고 가정합니다. –

답변

0

대화 상자를 닫는 데 아무 것도하지 않습니다. 단추를 설정하면 기본 동작은 클릭 할 때 대화 상자를 닫는 것이지만이 경우 사용자 지정 OnItemClickListener가있는 사용자 지정보기를 사용하고 있습니다.

onItemClick() -method에서 alert.dismiss();을 호출하여 명시 적으로 대화 상자를 닫을 수 있습니다.

1

onItemClick(...) 메서드 내에서 alert.dismiss()으로 전화해야한다고 생각합니다.

AlertDialog.Builder miaAlert = new AlertDialog.Builder(this); 

final ListView lV = new ListView(this); 
miaAlert.setTitle("Choose Valuta"); 
miaAlert.setView(lV); 
miaAlert.setCancelable(false); 

final AlertDialog alert = miaAlert.create(); 

lV.setOnItemClickListener(new OnItemClickListener() { 
    public void onItemClick(AdapterView<?> parent, View v, 
      int position, long id) { 

     String riga = String.valueOf(id); 
     String confr = vdb.getRecord(riga,2); 
     System.out.println("position= " + position + "/id= " + id+"/nome= "+confr); 
     new_valuta = vdb.getRecord(riga,2); 
     listdb.update("9", "Valuta", new_valuta, "2"); 
     c_list.requery(); 

     alert.dismiss(); 

    } 
}); 

alert.show(); 

이것은 물론, 추가 커서 관리 코드 : 당신이 무엇을 놓치고 있는지

2

실제로 대화 상자를 닫습니다 호출입니다.

+0

이것이 제가 찾고 있던 것입니다. 감사!! –

0

사용 alert.dismiss()의 대화