[英]How to use 'myLayout.addView(View v)' inside onPostExecute method in AsyncTask
[英]How to create a method inside the onPostExecute?
我試圖將其他按鈕放在onClick中
這是onClick
@Override
public void onClick(View view) {
ettext.getText().toString();
viewword.getText().toString();
select();
if(viewword.equals("")) {
Toast.makeText(getBaseContext(), "Does not exist in database.1", Toast.LENGTH_LONG).show();
}else{
sendChatMessage();
}
}
這是onPostExecute
@Override
protected void onPostExecute(String result) {
TextView disp = (TextView) findViewById(R.id.view);
try {
JSONObject json_data = new JSONObject(result);
word = json_data.getString("server_response");
disp.setText(word);
} catch (JSONException e) {
disp.setText("");
}
}
問題在於該應用程序未讀取if else語句,而是繼續執行onPostExecute。 我的解決方案是在onPostExecute內創建一個方法,但我不知道如何。
這里的問題不是onPostExecute,而是您的代碼。
viewword.getText()。toString();
這只是一個String值,在檢查它是否為null時,需要將其存儲在某個變量中。 因此,您的代碼應為
String checkVariable =viewword.getText().toString(); if(checkVariable.equals(""){ \\\\your code}
要么
if(viewword.getText().toString().equals("")
希望這可以幫助 :)
您不能在方法中創建方法,可以在AsyncTask
類中創建方法並在onPostExecute
方法中調用它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.