如何插入一个字符串值到对话框消息?对话框、消息、字符串值

由网友(会傲)分享简介:我有一个EDITTEXT和一个按钮,如果我输入ABC,然后按下按钮,它就会存储在我的数据库中的值,并会打开一个dielog框说它得到了成功的插入,但在对话框中我也想展示什么让插入,所以继承人code: 的EditText texto =(EditText上)findViewById(R.id.etAdd);最后弦乐re...

我有一个EDITTEXT和一个按钮,如果我输入ABC,然后按下按钮,它就会存储在我的数据库中的值,并会打开一个dielog框说它得到了成功的插入,但在对话框中我也想展示什么让插入,所以继承人code:

 的EditText texto =(EditText上)findViewById(R.id.etAdd);最后弦乐resultado = texto.getText()的toString()。按钮添加=(按钮)findViewById(R.id.bAdd);add.setOnClickListener(新OnClickListener(){    公共无效的onClick(视图v){        // TODO自动生成方法存根        尝试{            //睁开OU CRIA UMA数据库COM诺姆德:dbtest.db            DB = openOrCreateDatabase(dbtest.db,Context.MODE_PRIVATE,NULL);            尝试{                db.insert(usuarioorigem,resultado,NULL);                ShowMessage(Mensagens,Inserido+ resultado +COM Sucesso的!);            } {最后            }        } {最后        }    }}); 

解决方案

关键是要检查的插入操作

 的EditText texto =(EditText上)findViewById(R.id.etAdd);            按钮添加=(按钮)findViewById(R.id.bAdd);            add.setOnClickListener(新OnClickListener(){                公共无效的onClick(视图v){                    // TODO自动生成方法存根                    尝试{                        //睁开OU CRIA UMA数据库COM诺姆德:dbtest.db                        DB = openOrCreateDatabase(dbtest.db,Context.MODE_PRIVATE,NULL);                        字符串resultado = texto.getText()的toString()。                        尝试{                            长期结果= db.insert(usuarioorigem,resultado,NULL);                            如果(结果== -1){                               ShowMessage(错误插入); //对不起英语在这里,可能是ü可以使用inserido                            }                            其他{                               ShowMessage(Mensagens Inserido+ resultado +COM Sucesso的!);                            }                        }最后{                        }                }最后{                }                }            });    私人无效ShowMessage(弦乐味精){        Toast.makeText(这一点,味精,Toast.LENGTH_LONG).show();    } 

如何关闭打开文件安全警告

I have a editText and a button, if i type "abc" and hit the button it will store the value in my database and will open a dielog box saying it got insert successfully but in the dialog box i also want to show what got insert, so heres the code:

EditText texto = (EditText) findViewById(R.id.etAdd);
final String resultado = texto.getText().toString();

Button add = (Button) findViewById(R.id.bAdd);
add.setOnClickListener(new OnClickListener() {

    public void onClick(View v) {
        // TODO Auto-generated method stub
        try {
            //Abre ou Cria uma database com nome de: "dbtest.db"
            db = openOrCreateDatabase("dbtest.db", Context.MODE_PRIVATE, null);

            try {
                db.insert("usuarioorigem", resultado, null);
                ShowMessage("Mensagens","Inserido" +resultado+ "com sucesso!");
            } finally {

            }
        } finally {

        }
    }
});

解决方案

The key is to check for the success of insert operation

   EditText texto = (EditText) findViewById(R.id.etAdd);

            Button add = (Button) findViewById(R.id.bAdd);
            add.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    try{
                        //Abre ou Cria uma database com nome de: "dbtest.db"
                        db = openOrCreateDatabase("dbtest.db", Context.MODE_PRIVATE, null);
                        String resultado = texto.getText().toString();

                        try{
                            long result = db.insert("usuarioorigem", resultado, null);
                            if(result == -1){
                               ShowMessage("Error in Insert"); //sorry for english here, may be u can use inserido
                            }
                            else{
                               ShowMessage("Mensagens Inserido" +resultado+ "com sucesso!");
                            }
                        }finally{

                        }
                }finally{

                }
                }
            });


    private void ShowMessage(String msg){
        Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
    }

阅读全文

相关推荐

最新文章