[英]Save data from Dialog Box to String in Android Studio
Can Anyone tell me how to save data of Dialog Box into String.谁能告诉我如何将对话框的数据保存到字符串中。 I am Created one QR Code Scanning App in which I want store data which scanned by QR code.
我创建了一个 QR 码扫描应用程序,我想在其中存储通过 QR 码扫描的数据。 I am tried following code but showing an error when trying to to get data from dialog box to string.
我尝试使用以下代码,但在尝试从对话框获取数据到字符串时显示错误。 Error on this Line String user_data = data.getText().toString();
此行错误字符串 user_data = data.getText().toString(); at getText() .
在getText() 。 Please Tell me how resolve this error.
请告诉我如何解决此错误。
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (result!=null && result.getContents()!=null){
new AlertDialog.Builder(all_Entries.this)
.setTitle("Customer Information")
.setMessage(result.getContents())
//Save Button
.setPositiveButton("Save", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
addDataToDatabase();
}
private void addDataToDatabase() {
String user_data = data.getText().toString();
// Here getText() Function is not working Showing an Error : **Cannot resolve method 'getText' in 'Intent'**
UserData userData = new UserData(user_data);
repository = new MyRepository(MyDatabase.getInstance(getApplicationContext()).myDao());
repository.addUser(userData);
Toast.makeText(all_Entries.this, "Data is Saved", Toast.LENGTH_SHORT).show();
}
})
//Save Button End
.setNegativeButton("Cancle", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).create().show();
}
super.onActivityResult(requestCode, resultCode, data);
}
@Nullable Intent data
data is not a EditText
or TextView
it's an Intent
so I think data.toString()
will work. @Nullable Intent data
数据不是EditText
或TextView
它是一个Intent
所以我认为data.toString()
会起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.