转轮怎么在对话框中使用

  

转轮怎么在对话框中使用?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

转轮在对话框中的使用,对话框中关于视图的xml布局。

& lt; ? xml  version=?.0“,编码=皍tf-8" ?比;   & lt; LinearLayout  xmlns: android=癶ttp://schemas.android.com/apk/res/android"   ,android: layout_width=癿atch_parent"   ,android: layout_height=癿atch_parent"   ,android:取向=皏ertical"   ,android:填充=?6 dp"比;   & lt;转轮   android:才能id=癅 + id/spinner"   android:才能layout_width=癿atch_parent"   android:才能layout_height=皐rap_content"   android:才能layout_marginBottom=? dp",/比;   EditText & lt;   android:才能id=癅 + id/edit"   android:才能layout_width=癿atch_parent"   android:才能layout_height=皐rap_content"   android:才能填充=? dp",/比;   & lt;/LinearLayout>

对话框初始化,加载,显示出来的完整代码(包含对转轮进行适配器设置)。

private  void  showAlertDialog (), {   ,View  View =, LayoutInflater.from(这).inflate (R.layout.dialog_add_notebook, null);   ,Spinner  Spinner =, view.findViewById (R.id.spinner);   ,ArrayAdapter arrayAdapter =, new  ArrayAdapter<祝辞(R.layout.simple_spinner_item,这一点,还以为,android.R.id.text1,类别);   ,spinner.setAdapter (arrayAdapter);   ,spinner.setOnItemSelectedListener (new  AdapterView.OnItemSelectedListener (), {   @Override才能   public 才能;void  onItemSelected (AdapterView<?祝辞,母公司,View 看来,,int 位置,,long  id), {   ,,Toast.makeText (MainActivity.this,“选中的分类是:,“,+,categories.get(位置),Toast.LENGTH_LONG),告诉();   ,,}   ,   @Override才能   public 才能;void  onNothingSelected (AdapterView<?祝辞,父母),{   ,   ,,}   ,});   ,new  AlertDialog.Builder(这)   ,,.setTitle(“提示“)   ,,.setView(视图)   ,,.setPositiveButton (android.R.string.ok, new  DialogInterface.OnClickListener (), {   ,,@Override   ,,,public  void  onClick (DialogInterface 对话框,int 它),{   ,,,,dialog.dismiss ();   ,,,}   ,,})   ,,,告诉();   }

只能说转轮在对话框中,显示出来的效果一般般,即使通过自定义项布的局,调整填充、感觉效果也不是特别让人满意。

截张图:

, 转轮怎么在对话框中使用“> </p> <p>在Github上找到一个不错的项目,https://github.com/Lesilva/BetterSpinner。</p> <p>修改代码,替换为BetterSpinner。</p> <p>在app/build.gradle中添加</p> <p> <代码>编译' com.weiwangcn.betterspinner:图书馆:1.1.0 # 39;</代码> </p> <p> xml布局文件修改为:<br/> </p> <pre类= & lt; ? xml  version=?.0“,编码=皍tf-8" ?比;   & lt; LinearLayout  xmlns: android=癶ttp://schemas.android.com/apk/res/android"   ,android: layout_width=癿atch_parent"   ,android: layout_height=癿atch_parent"   ,android:取向=皏ertical"   ,android:填充=?6 dp"比;   & lt; com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner   android:才能id=癅 + id/spinner"   android:才能layout_width=癿atch_parent"   android:才能layout_height=皐rap_content"   android:才能layout_marginBottom=癅dimen/activity_vertical_margin"   android:才能暗示=癅string/notebook_choose_notebook_hint",/比;   EditText & lt;   android:才能id=癅 + id/edit"   android:才能layout_width=癿atch_parent"   android:才能layout_height=皐rap_content"   android:才能填充=? dp",/比;   & lt;/LinearLayout>

显示对话的方法调整为

public  void  onClickedAddNotebook (final  String  parentNotebookId,, List,笔记本电脑),{   ,View  View =, LayoutInflater.from (mActivity) .inflate (R.layout.dialog_add_notebook, null);   ,final  EditText  mEdit =, (EditText), view.findViewById (R.id.edit);   ,final  MaterialBetterSpinner  spinner =, (MaterialBetterSpinner), view.findViewById (R.id.spinner);   ,final  List tempNotebooks =, new  ArrayList<在();   ,tempNotebooks.clear ();   ,tempNotebooks.addAll(笔记本);   ,Notebook  rootNoteBook =, new 笔记本();   ,rootNoteBook.setTitle (mActivity.getString (R.string.notebook_default_root_notebook_title));   ,tempNotebooks.add (0,, rootNoteBook);   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

转轮怎么在对话框中使用