最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Spinner怎么在Dialog中使用

Spinner怎么在Dialog中使用?很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。

創(chuàng)新互聯(lián)建站成都網(wǎng)站建設(shè)按需網(wǎng)站策劃,是成都網(wǎng)站設(shè)計(jì)公司,為資質(zhì)代辦提供網(wǎng)站建設(shè)服務(wù),有成熟的網(wǎng)站定制合作流程,提供網(wǎng)站定制設(shè)計(jì)服務(wù):原型圖制作、網(wǎng)站創(chuàng)意設(shè)計(jì)、前端HTML5制作、后臺程序開發(fā)等。成都網(wǎng)站改版熱線:18982081108

Spinner在Dialog中的使用,Dialog中關(guān)于view的xml布局。



 
 

dialog初始化,加載,顯示出來的完整代碼(包含對Spinner進(jìn)行Adapter設(shè)置)。

private void showAlertDialog() {
 View view = LayoutInflater.from(this).inflate(R.layout.dialog_add_notebook, null);
 Spinner spinner = view.findViewById(R.id.spinner);
 ArrayAdapter arrayAdapter = new ArrayAdapter<>(this, R.layout.simple_spinner_item, android.R.id.text1, categories);
 spinner.setAdapter(arrayAdapter);
 spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  @Override
  public void onItemSelected(AdapterView parent, View view, int position, long id) {
   Toast.makeText(MainActivity.this, "選中的分類是: " + categories.get(position), Toast.LENGTH_LONG).show();
  }
 
  @Override
  public void onNothingSelected(AdapterView parent) {
 
  }
 });
 new AlertDialog.Builder(this)
   .setTitle("提示")
   .setView(view)
   .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
     dialog.dismiss();
    }
   })
   .show();
}

只能說spinner在dialog中,顯示出來的效果一般般,即使通過自定義item布局,調(diào)整padding,感覺效果也不是特別讓人滿意。

截張圖:

 Spinner怎么在Dialog中使用

在Github上找到一個不錯的項(xiàng)目,https://github.com/Lesilva/BetterSpinner。

修改代碼,替換為BetterSpinner。

在app/build.gradle中添加

compile ‘com.weiwangcn.betterspinner:library:1.1.0'

xml布局文件修改為:



 
 

顯示dialog的方法調(diào)整為

public void onClickedAddNotebook(final String parentNotebookId, List notebooks) {
 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(notebooks);
 Notebook rootNoteBook = new Notebook();
 rootNoteBook.setTitle(mActivity.getString(R.string.notebook_default_root_notebook_title));
 tempNotebooks.add(0, rootNoteBook);
 SpinnerArrayAdapter adapter = new SpinnerArrayAdapter(view.getContext(), tempNotebooks) {
  @Override
  public String itemToString(Notebook item) {
   return item.getTitle();
  }
 };
 spinner.setAdapter(adapter);
 spinner.setText(rootNoteBook.getTitle());
 new AlertDialog.Builder(mActivity)
   .setTitle(R.string.add_notebook)
   .setView(view)
   .setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
     dialog.dismiss();
     addNotebook(mEdit.getText().toString(), getNotebookId(tempNotebooks, spinner.getText().toString()));
    }
   })
   .show();
}

細(xì)微之處的api有所變化,用法大多差不多,看一下最終的預(yù)覽效果,覺得還是挺materialDesign風(fēng)的。

Spinner怎么在Dialog中使用

看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進(jìn)一步的了解或閱讀更多相關(guān)文章,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對創(chuàng)新互聯(lián)的支持。


當(dāng)前題目:Spinner怎么在Dialog中使用
分享URL:http://fisionsoft.com.cn/article/ipghcg.html