new MapsActivity.GetDirecoes().execute(latRepr, lngRepr);
public class GetDirecoes extends AsyncTask<String, Void, Void> implements Serializable {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MapsActivity.this);
pDialog.setMessage("Aguarde...");
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected Void doInBackground(String... params) {
HttpHandler sh = new HttpHandler();
txtDistanciaTotal = (TextView) findViewById(R.id.txtDistanciaTotal);
txtDuracaoTotal = (TextView) findViewById(R.id.txtDuracaoTotal);
instrucoes = (TextView) findViewById(R.id.Instrucoes);
String url1 = "https://maps.googleapis.com/maps/api/directions/json?origin=";
String url2 = "&destination=";
String url3 = "&key=AIzaSyBh6tmMrC6QaHMJewFGvGc8xOjc0WMajxQ&language=pt";
String latRepr = params[0];
String lngRepr = params[1];
final String jsonStr = sh.makeServiceCall(url1 + mylatitude + "," + mylongitude + url2 + latRepr + "," + lngRepr + url3);
Log.e(TAG, "Link: " + url1 + mylatitude + "," + mylongitude + url2 + latRepr + "," + lngRepr + url3);
Log.e(TAG, "Resposta do URL: " + jsonStr);
if (jsonStr != null) {
try {
JSONObject root = new JSONObject(jsonStr);
JSONArray routes = root.optJSONArray("routes");
if (routes != null) {
JSONObject singleRout = (JSONObject) routes.get(0);
JSONArray legs = (JSONArray) singleRout.get("legs");
if (legs != null) {
JSONObject singleLeg = (JSONObject) legs.get(0);
//Distancia total
JSONObject distanceT = (JSONObject) singleLeg.get("distance");
if (distanceT != null) {
distT = distanceT.getString("text");
}
//Duracao Total
JSONObject durationT = (JSONObject) singleLeg.get("duration");
if (durationT != null) {
duraT = durationT.getString("text");
}
JSONArray steps = (JSONArray) singleLeg.get("steps");
if (steps != null) {
for (int j = 0; j < steps.length(); j++) {
JSONObject singleStep = (JSONObject) steps.get(j);
HashMap<String, String> direcao = new HashMap<>();
JSONObject distance = (JSONObject) singleStep.get("distance");
//Distancia
if (distance != null) {
String dist = distance.getString("text");
direcao.put("textDi", dist);
}
//Duraçao
JSONObject duration = (JSONObject) singleStep.get("duration");
if (duration != null) {
String dura = duration.getString("text");
direcao.put("textDu", dura);
}
//Polylines
JSONObject singlePolyline = (JSONObject) singleStep.get("polyline");
if (singlePolyline != null) {
String points = singlePolyline.getString("points");
Map<String, String> caminho = new HashMap<>();
caminho.put("points", points);
listaPolylines.add((HashMap<String, String>) caminho);
}
//Instruções
String html = singleStep.getString("html_instructions");
direcao.put("html_instructions2", html);
listaDirecoes.add(direcao);
}
}
}
}
} catch (final JSONException e) {
Log.e(TAG, "ERROR: " + e.getMessage());
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), "ERROR: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
} else {
Log.e(TAG, "ERROR");
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), "Verifique a sua ligação à internet", Toast.LENGTH_LONG).show();
}
});
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
final ListView list = (ListView) (MapsActivity.this).findViewById(R.id.listaDirecoes);
ListAdapter adapter = new SimpleAdapter(
(MapsActivity.this),
listaDirecoes,
R.layout.list_item_direcoes,
new String[]{"html_instructions2", "textDi", "textDu"},
new int[]{R.id.Instrucoes, R.id.txtDistancia, R.id.txtDuraçao});
list.setAdapter(adapter);
txtDuracaoTotal.setText(duraT);
txtDistanciaTotal.setText(distT);
fazerCaminho(listaPolylines);
if (pDialog.isShowing()) {
pDialog.dismiss();
}
bottom_sheet.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
Log.v(TAG, "Parent Touch");
findViewById(R.id.listaDirecoes).getParent().requestDisallowInterceptTouchEvent(false);
return false;
}
});
listaDirecoesChild.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
Log.v(TAG, "CHILD TOUCH");
// Disallow the touch request for parent scroll on touch of child view
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
}
}
您可以通过从另一个类调用一个类
private Activity activity;
您应该初始化,活动
从另一个类中,将其称为:
((DetailsActivity) activity).refreshList(latRepr, lngRepr);
public void refreshList(String latRepr, String lngRepr) {
new GetDirecoes().execute(latRepr, lngRepr);
}
问题内容: 听起来很简单,但我无法使其正常工作。我有两个活动。第一个是表单,第二个是根据在第一个活动中输入的值显示JSON文件中的数据。 因此,我正在尝试制作一个简单的版本。我有一个EditText和一个按钮,因此当他们按下按钮时,EditText中的内容将出现在下一个活动的TextView中。 到目前为止,这是我的代码: 主要活动 主要XML 第二次活动 第二个XML 通过这种方式,我为Edit
在我的程序中,我有一个当应用程序打开时启动的活动。如果我再打开几个活动,我怎么能回到主活动?在意图过滤器中,活动的名称是“android.intent.action.MAIN”,它不允许我在上面调用start Active()。我该怎么办?
我正在写一个Android应用程序,有Java和静态编程语言活动。我希望从静态编程语言移动到Java,已经完成了,现在我希望回到静态编程语言活动,我找不到具体的代码。 我的应用程序名称是starter,Kotlin活动是MainActivity。kt和java类是face_detect。JAVA我已经试过:` ` 我希望单击face_detect上的按钮。java,这将把我带到MainActivi
我有个错误 //类别2是片段
本文向大家介绍如何在python中执行另一个py文件,包括了如何在python中执行另一个py文件的使用技巧和注意事项,需要的朋友参考一下 使用命令:os.system('python file_name.py') 解释:os.system是执行当前的系统命令 1、拿windows系统举例: 2、linux: 其他方法: execfile('xx.py'),括号内为py文件路径; 如果专需要传参数