我的代码有问题。我有一个带有EditText的活动,当该活动第一次打开时,我希望将EditText的值传递给我的服务器并收到一个答案。
问题是,如果我在onCreate ()中调用该方法,它将无法工作。
相反,如果我从button的click ()事件调用该方法,它就可以工作。
有没有办法从onCreate ()调用该方法并显示EditText的内容
这是我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
First_Name = (EditText)findViewById(R.id.editText50);
parseContent = new ParseContentRistoratore(this);
preferenceHelper = new PreferenceHelperRistoratore(this);
CheckEditTextIsEmptyOrNot();
UserRegisterFunction(F_Name_Holder);
prova = (Button) findViewById(R.id.button10);
// If EditText is not empty and CheckEditText = True then this block will execute.
prova.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
//REGISTRATION
@RequiresApi(api = Build.VERSION_CODES.CUPCAKE)
public void UserRegisterFunction(final String fk_id_ristorante){
class UserRegisterFunctionClass extends AsyncTask<String,Void,String> {
@Override
protected void onPostExecute(String httpResponseMsg) {
super.onPostExecute(httpResponseMsg);
if(httpResponseMsg.equalsIgnoreCase("Prova gratuita terminata")){
// finish(); con finish(); l'attività finisce
Intent intent = new Intent(Main3Activity.this, Versione_scaduta.class);
startActivity(intent);
}
}
//REGISTRATION
@Override
protected String doInBackground(String... params) {
hashMap.put("fk_id_ristorante",params[0]);
finalResult = httpParse.postRequest(hashMap, HttpURLRegister);
return finalResult;
}
}
UserRegisterFunctionClass userRegisterFunctionClass = new UserRegisterFunctionClass();
userRegisterFunctionClass.execute(fk_id_ristorante);
}
//REGISTRAZIONE
public void CheckEditTextIsEmptyOrNot(){
F_Name_Holder = First_Name.getText().toString();
if(TextUtils.isEmpty(F_Name_Holder) )
{
CheckEditText = false;
}
else {
CheckEditText = true ;
}
}
@Override
protected void onResume() {
super.onResume();
AccountKit.getCurrentAccount(new AccountKitCallback<Account>() {
@Override
public void onSuccess(Account account) {
//editUserId = (EditText)findViewById(R.id.editUserEmail);
// editUserId.setText(String.format("Email Id %s",account.getEmail()));
First_Name.setText(String.format("r%s", account.getId()));
}
@Override
public void onError(AccountKitError accountKitError) {
}
});
}
}如果你做不到,我想知道些别的。
为什么在我的PHP代码中,如果我从IF Cycle中删除Else,当它在Android studio上启动时,代码不能工作
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
include 'config.php';
$con = mysqli_connect($HostName,$HostUser,$HostPass,$DatabaseName);
$fk_id_ristorante = $_POST['fk_id_ristorante'];
$CheckSQL = "SELECT * FROM R_Iscrizioni WHERE data_scadenza < CURDATE() AND fk_id_ristorante='$fk_id_ristorante' AND pagamento = 'No' ";
$check = mysqli_fetch_array(mysqli_query($con,$CheckSQL));
if(isset($check)){
echo 'Prova gratuita terminata';
}
else {
echo 'Hello';
}
}
mysqli_close($con);
?>发布于 2019-03-08 20:48:00
您需要做的就是使用CountDownTimer加载系统,并准备好让代码以正确的方式执行。
希望这对你有帮助。
https://stackoverflow.com/questions/55059457
复制相似问题