i try to make my 1st AsyncTask
in App. This application should download from 2 field numbers, then multiplication and display score in 3rd field.
It is easy, but i want to learn how to use AsyncTask and i want this metod(for multiplication) put in other thread.
In my opinion it look fine, but AndroidStudio underline my class MyTask
. And suggets impement that same method... :
@Override
protected Void doInBackground(Double... params) {
return null;
}
Can i ask for tips, how i should do now ?
public class MainActivity extends AppCompatActivity {
private Button button;
private EditText editText,editText2,editText3;
private String a,b,c;
private Double x1,x2,x3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
editText = (EditText) findViewById(R.id.editText);
editText2 = (EditText) findViewById(R.id.editText2);
editText3 = (EditText) findViewById(R.id.editText3);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
a = editText.getText().toString();
b = editText2.getText().toString();
x1 = Double.parseDouble(a);
x2 = Double.parseDouble(b);
calc();
}
});
}
private class MyTask extends AsyncTask<Double, Void, Void>{
@Override
protected Void doInBackground(Double x1, Double x2) {
x3 = x1 * x2;
c = String.valueOf(x3);
editText3.setText(c);
return null;
}
}
private void calc() {
new MyTask().execute();
}
}