gpt4 book ai didi

java - 如何在onPostExecute中创建一个方法?

转载 作者:行者123 更新时间:2023-12-02 03:23:22 24 4
gpt4 key购买 nike

我尝试将 if else 放在 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 checkVariable =viewword.getText().toString();
if(checkVariable.equals(""){
\\your code}

if(viewword.getText().toString().equals("")

希望这有帮助:)

关于java - 如何在onPostExecute中创建一个方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39317274/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com