zoukankan      html  css  js  c++  java
  • 带输入框(EditText)的AlertDialog

    一、Main Class:
    public void search() {
       Builder dialog 
    = new AlertDialog.Builder(this);
       LayoutInflater inflater 
    = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
       LinearLayout layout 
    = (LinearLayout)inflater.inflate(R.layout.dialogview, null);
       dialog.setView(layout);
       et_search 
    = (EditText)layout.findViewById(R.id.searchC);
       dialog.setPositiveButton(
    "查找"new DialogInterface.OnClickListener() {
        
    public void onClick(DialogInterface dialog, int which) {
         String searchC 
    = et_search.getText().toString();
         Intent intent 
    = new Intent();
         Bundle bundle 
    = new Bundle();
         bundle.putString(
    "search", searchC);
         intent.putExtras(bundle);
         intent.setClass(ViewResultActivity.
    this, SearchResult.class);
         ViewResultActivity.
    this.startActivity(intent);
        }
       });
      
       dialog.setNegativeButton(
    "取消"new DialogInterface.OnClickListener() {
        
    public void onClick(DialogInterface dialog, int which) {
        
        }
       
       });
       dialog.show();
    }

    二、dialogview.xml
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation
    ="vertical"
    android:layout_width 
    = "fill_parent"
    android:layout_height 
    = "fill_parent"
    >
    <EditText
       android:id 
    = "@+id/searchC"
       styles 
    = "@style/edittext_style1"
       android:layout_width 
    = "200px"
       android:layout_height 
    = "wrap_content"
       android:gravity 
    = "left"
       
    />

    </LinearLayout>
  • 相关阅读:
    Transaction 'IREG', Abend 'APCT', at '????'.
    CICS中设置是否具有可修改性
    常用命令总结
    常用语句总结
    _func_
    数组排序返回索引-python和c++的实现
    数组的并行求和-cuda实现
    Pytorch 多GPU训练-多计算节点并行-All you need
    Pytorch 多GPU训练-单运算节点-All you need
    Windows 编程中的问题
  • 原文地址:https://www.cnblogs.com/tt_mc/p/1785793.html
Copyright © 2011-2022 走看看