2014-06-18 1 views
0

회 전자를 제목으로 포함하는 AlertDialog (Textvie 연습을 클릭했을 때 나타납니다)를 만들려고합니다. 회 전자에서 다른 항목을 선택하면 대화 상자 목록의 내용이 변경됩니다. 이 방법은 나를 위해 매우 복잡한 것 (심지어는 작동하지 않습니다) 때문에회 전자를 대화 상자 제목으로 사용

exercise = (TextView)findViewById(R.id.add_exerc); 
exercise.setText("TEST"); 
initExerOCL(); //init the OnItem 

private void initExerOCL(){ 
    exercise.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      //diaTitle is used for the String[] from which to create the dialogList 
      AlertDialog a = showListCheckPickerDialog(diaTitle); 
      a.show(); 
     } 
    }); 
} 

public AlertDialog showListCheckPickerDialog(int i){ 
    mSelectedItems = new ArrayList(); //saves selected items 

    LayoutInflater inflater = getLayoutInflater(); 
    View v = inflater.inflate(R.layout.add_dia_spinner_title, null); 
    s = (Spinner) findViewById(R.id.add_dia_t); 
    ArrayAdapter<CharSequence> adapterS = ArrayAdapter.createFromResource(this, 
      R.array.trainings, R.layout.spinner_item); 
    adapterS.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
    s.setAdapter(adapterS); 
    s.setOnItemSelectedListener(this); 

    AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    builder.setTitle(R.string.a_add) 
    //set the View for the spinner 
    .setCustomTitle(v) 
    .setMultiChoiceItems(diaTitle, null, 
      new DialogInterface.OnMultiChoiceClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int which, 
       boolean isChecked) { 
      if (isChecked) { 
       // If the user checked the item, add it to the selected items 
       mSelectedItems.add(which); 
      } else if (mSelectedItems.contains(which)) { 
       // Else, if the item is already in the array, remove it 
       mSelectedItems.remove(Integer.valueOf(which)); 
      } 
     } 
    }) 
    // Set the action buttons 
    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int id) { } 
    }) 
    .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int id) { } 
    }); 
    return builder.create(); 
} 

나는, 누군가가 솔루션이나 더 좋은 방법을 nows 바랍니다. 감사!

답변

0

(자세한 http://developer.android.com/guide/topics/ui/actionbar.html#Dropdown에 대한 문서 참조) 대신 단지 프로그래밍 방식 스피너를 생성하고 사용자 정의 제목에 추가 레이아웃을 팽창 원하는 내용으로 활동 내부의 회 전자, 설정 드롭 다운 네비게이션을 구현하는 .

샘플 :

Spinner s2 = new Spinner(this); 
    ArrayAdapter<CharSequence> adapterS = ArrayAdapter.createFromResource(this, 
      R.array.trainings, R.layout.spinner_item); 
    adapterS.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
    s.setAdapter(adapterS); 
    s.setOnItemSelectedListener(this); 

    AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    builder.setTitle("hello") 
    //set the View for the spinner 
    .setCustomTitle(s2) 
    // Set the action buttons 
    .setPositiveButton("okie", new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int id) { } 
    }) 
    .setNegativeButton("lawl", new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int id) { } 
    }) 
+0

감사합니다! 이것은 문제를 해결했습니다! – insch