Answer the question
In order to leave comments, you need to log in
How to pass a variable from one class to another?
Good afternoon, android studio ran into a problem, you need to pass a variable from one class to another. The variable in the main class looks like this:
final Editable[] tp = {};
tp[0]=tt.getText(); tt is a normal editText;
and pass it to this class:
.........
public class TaxiApiAsync extends AsyncTask<String, Void, TaxiResponce> {
private Context context;
private String tp;
public TaxiApiAsync(Context context) {
this.context = context;
}
@Override
protected TaxiResponce doInBackground(String... voids) {
// получили json
String jsonResponce = null;
try {
FullscreenActivity1 f = new FullscreenActivity1();
//f.getResources();
//f.
jsonResponce = new TaxiApi().withPhone(ПЕРЕДАТЬ СЮДАА!!!!!!!!!!!!!!!).withAdress("Фонтанка 33").done().send();
} catch (IOException e) {
e.printStackTrace();
}
// распарсили json в класс, чтоб можно было брать данные из обычных
// переменных
TaxiResponce taxiResponce = new Gson().fromJson(jsonResponce, TaxiResponce.class);
return taxiResponce;
}
@Override
protected void onPostExecute(TaxiResponce taxiResponce) {
if (taxiResponce.getCode() == 0){
Toast.makeText(context, "Заказ добавлен...", Toast.LENGTH_SHORT).show();
}else if (taxiResponce.getCode() == 100){
Toast.makeText(context, "Такой заказ уже есть, может хватит жать кнопку?!!...", Toast.LENGTH_SHORT).show();
}
}
}
Answer the question
In order to leave comments, you need to log in
-new TaxiApiAsync(),execute("номер телефона");
@Override
protected TaxiResponce doInBackground(String... strs) {
// получили json
String jsonResponce = null;
try {
jsonResponce = new TaxiApi().withPhone(strs[0]).withAdress("Фонтанка 33").done().send();
} catch (IOException e) {
e.printStackTrace();
}
// распарсили json в класс, чтоб можно было брать данные из обычных
// переменных
TaxiResponce taxiResponce = new Gson().fromJson(jsonResponce, TaxiResponce.class);
return taxiResponce;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question