在Android的一个对话框中设置多个文本框 [英] Set multiple text boxes in a dialog in android

查看:684
本文介绍了在Android的一个对话框中设置多个文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个对话框,就像是含有两个文本框和两个按钮的登录界面。我能创建它,但我的问题是两个编辑文本框彼此重叠(第二编辑文本框重叠的第一个)。这可能是一个简单的,但由于即时通讯新到Android IM坚持it.Pls帮我解决这个问题。这里是源$ C ​​$ C

 公共类LoginActivity延伸活动{
    / **第一次创建活动时调用。 * /
    @覆盖

    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);
        按钮BTN =(按钮)findViewById(R.id.btn_Login);
        btn.setOnClickListener(新View.OnClickListener(){

            @覆盖
            公共无效的onClick(视图v){
                的ShowDialog(0);

            }
        });
    }

        受保护的对话框onCreateDialog(INT ID)
        {
        最后AlertDialog.Builder警报=新AlertDialog.Builder(本);
        最后的EditText输入=新的EditText(本);
        最后的EditText输入1 =新的EditText(本);
        alert.setIcon(R.drawable.icon);
        alert.setTitle(登录);
        alert.setView(输入);
        alert.setView(输入1);

        alert.setView(输入1);
        alert.setPositiveButton(OK,新DialogInterface.OnClickListener(){
            公共无效的onClick(DialogInterface对话,诠释whichButton){
                字符串值= input.getText()的toString()修剪()。
                Toast.makeText(getApplicationContext(),价值,Toast.LENGTH_SHORT).show();
                }});
        alert.setNegativeButton(取消,
                新DialogInterface.OnClickListener(){
            公共无效的onClick(DialogInterface对话,诠释whichButton){
                dialog.cancel(); }});
        返回alert.create();
        }
    }
 

解决方案

您可以创建一个布局XML的对话框也是如此。在致电您的对话只是做:

  myDialog.setContentView(R.layout.my_dialog_layout);
 

I am creating a dialog box which is like a login screen containing two text boxes and two buttons. I am able to create it but my problem is the two edit text boxes are overlapping with each other(Second edit text box is overlapping with the first one). It may be a simple one but since i m new to android i m stuck with it.Pls help me to solve it. Here is the source code

public class LoginActivity extends Activity {
    /** Called when the activity is first created. */
    @Override

    public void onCreate(Bundle savedInstanceState) {                        
        super.onCreate(savedInstanceState);                         
        setContentView(R.layout.main);  
        Button btn= (Button) findViewById(R.id.btn_Login);
        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                showDialog(0);

            }
        });
    }

        protected Dialog onCreateDialog(int id)
        {
        final AlertDialog.Builder alert = new AlertDialog.Builder(this);                        
        final EditText input = new EditText(this); 
        final EditText input1 = new EditText(this);
        alert.setIcon(R.drawable.icon);
        alert.setTitle("Login");
        alert.setView(input);   
        alert.setView(input1);

        alert.setView(input1);
        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {             
            public void onClick(DialogInterface dialog, int whichButton) {              
                String value = input.getText().toString().trim();                       
                Toast.makeText(getApplicationContext(), value, Toast.LENGTH_SHORT).show();   
                }                     });                 
        alert.setNegativeButton("Cancel",                  
                new DialogInterface.OnClickListener() {                           
            public void onClick(DialogInterface dialog, int whichButton) {          
                dialog.cancel();    }     });         
        return alert.create();      
        } 
    }

解决方案

You can create a layout XML for dialog boxes as well. Before calling your Dialog just do:

myDialog.setContentView(R.layout.my_dialog_layout);

这篇关于在Android的一个对话框中设置多个文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆