如何插入一个字符串值到对话框消息? [英] How to insert a string value into a dialog message?
本文介绍了如何插入一个字符串值到对话框消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个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的!);
} {最后 }
} {最后 }
}
});
解决方案
关键是要检查的<一个成功href=\"http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#insert%28java.lang.String,%20java.lang.String,%20android.content.ContentValues%29\"相对=nofollow>插入操作
的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();
}
这篇关于如何插入一个字符串值到对话框消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文