Есть код 2 активити, они одинаковы с 1, но в первом spinner
, а во втором ListView
, так вот в первом у меня парсит 1 Json
в spinner
, мне надо, чтобы при нажатие на объект в spinner
, парсил уже из 2 активити, но в ListView
.
public class MainActivity2 extends AppCompatActivity {
private String TAG = MainActivity2.class.getSimpleName();
private ProgressDialog pDialog;
private Spinner spinner;
// URL to get contacts JSON
private static String url = "Тут URL первого Json";
ArrayList<HashMap<String, String>> contactList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
contactList = new ArrayList<>();
spinner = (Spinner) findViewById(R.id.spinner);
new GetContacts().execute();
}
/**
* Async task class to get json by making HTTP call
*/
private class GetContacts extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
pDialog = new ProgressDialog(MainActivity2.this);
pDialog.setMessage("Please wait...");
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected Void doInBackground(Void... arg0) {
HttpHandler sh = new HttpHandler();
// Making a request to url and getting response
String jsonStr = sh.makeServiceCall(url);
Log.e(TAG, "Response from url: " + jsonStr);
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
// Getting JSON Array node
JSONArray data = jsonObj.getJSONArray("data");
// looping through All Contacts
for (int i = 0; i < data.length(); i++) {
JSONObject c = data.getJSONObject(i);
String id = c.getString("id");
String ip = c.getString("ip");
String link = c.getString("link");
// tmp hash map for single contact
HashMap<String, String> contact = new HashMap<>();
// adding each child node to HashMap key => value
contact.put("id", id);
contact.put("ip", ip);
contact.put("link", link);
// adding contact to contact list
contactList.add(contact);
}
} catch (final JSONException e) {
Log.e(TAG, "Json parsing error: " + e.getMessage());
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),
"Json parsing error: " + e.getMessage(),
Toast.LENGTH_LONG)
.show();
}
});
}
} else {
Log.e(TAG, "Couldn't get json from server.");
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),
"Couldn't get json from server. Check LogCat for possible errors!",
Toast.LENGTH_LONG)
.show();
}
});
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// Dismiss the progress dialog
if (pDialog.isShowing())
pDialog.dismiss();
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(
MainActivity2.this, contactList,
R.layout.list_item, new String[]{"ip", "link",},
new int[]{R.id.name,
R.id.link});
spinner.setAdapter((SpinnerAdapter) adapter);
}
}
}
Оборудование для ресторана: новинки профессиональной кухонной техники
Частный дом престарелых в Киеве: комфорт, забота и профессиональный уход
Журнал можно представить как таблицу из трех колонок: "Дата", "Объект", "Комментарий пользователя"Журнал должен создаваться локально, а потом...
Не получается загрузить файлы xls и doc(старый Office) файл загружается, но он пустой и выскакивает сообщение конфлик версийС xlsx и docx все нормально