ProgressDialogの初期化では、LoginActivity.thisが囲みクラスではないことが示されています。 onPostExecute()メソッドでトーストが実行されず、getApplicationContext()メソッドを解決できません。getApplicationContext()メソッドを解決できません。LoginActivity.thisは囲みクラスではありません
public class LoginActivity extends AppCompatActivity {
EditText et1,et2;
Button b;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login2);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
et1=(EditText)findViewById(R.id.editText5);
et2=(EditText)findViewById(R.id.editText6);
b=(Button)findViewById(R.id.button2);
}
public void login(View view)
{
new BackgroundTask().execute(et1.getText().toString(),et2.getText().toString());
Toast.makeText(this,"Button",Toast.LENGTH_LONG).show();
}
}
class Background extends AsyncTask<String, Integer, Integer>
{
ProgressDialog progressDialog=new ProgressDialog(LoginActivity.this);;
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog.setMessage("Processing");
progressDialog.setTitle("Title");
progressDialog.show();
}
int check_point =0;
String resp="";
@Override
protected Integer doInBackground(String... params) {
try {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://192.168.1.6/login.php");
HttpResponse response = client.execute(post);
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String s;
while ((s = reader.readLine()) != null) {
resp=resp+s;
}
}
catch (Exception e)
{
System.out.print(e);
}
return check_point;
}
@Override
protected void onPostExecute(Integer integer) {
super.onPostExecute(integer);
progressDialog.dismiss();
Toast.makeText(getApplicationContext(),"ACtivity",Toast.LENGTH_LONG).show();
}
}
は、どのようにログイン(ビュービュー)実際のボタンインスタンスに関連付けられていますか? Toasts&System.out.printの代わりにLogを使用してください。 onPreExecuteからprogressDialogを初期化するのはなぜですか? AsyncTaskがLoginActivityの内部クラスであることを考慮して、なぜアクティビティコンテキストでprogressDialogを初期化し、アプリケーションコンテキストonPostExecuteを使用しますか? – randomuser
私は何をしていますか? –
"LoginActivity.this"の代わりにキーワード "this"を使用すると、問題が解決するはずです –