@run182

Как выбрать открыть страницу с записью из списка (Android)?

Вывожу через ListView список записей, используя запрос к серверу. Как открыть детальную страницу записи, куда передать id для этого?
class LoadAllPlaces extends AsyncTask<String, String, String> {

        /**
         * Перед началом фонового потока Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(AllPlacesActivity.this);
            pDialog.setMessage("Загрузка...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(false);
            pDialog.show();
        }

        /**
         * Получаем все продукт из url
         * */
        protected String doInBackground(String... args) {
            ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);

            NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
            if (activeNetwork != null && activeNetwork.isConnected()) {
                try{
                    String content = getContent(placeGetList);
                    try {
                        JSONArray values = new JSONArray(content);

                        if (1 == 1) {
                            // перебор всех продуктов
                            for (int i = 0; i < 10; i++) {
                                JSONObject products = values.getJSONObject(i);
                                String name = products.getString("NAME");
                                String address = products.getString(ADDRESS);
                                String id = product.getString("ID");

                                HashMap<String, String> map = new HashMap<String, String>();

                                // добавляем каждый елемент в HashMap ключ => значение
                                map.put(ID, id);
                                map.put(ADDRESS, name+" "+address);

                                // добавляем HashList в ArrayList
                                productsList.add(map);
                            }
                        } else {
                            // продукт не найден
                            // Запускаем Add New Product Activity
                            Intent i = new Intent(getApplicationContext(),
                                    NewPlaceActivity.class);
                            // Закрытие всех предыдущие activities
                            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            startActivity(i);
                        }
                    } catch (JSONException ex) {
                        ex.getMessage();
                    }
                } catch (IOException ex) {
                    ex.getMessage();
                }
            } else {
                HashMap<String, String> map = new HashMap<String, String>();
                map.put(ADDRESS, "Нет подключения к Интернету.");
                productsList.add(map);
            }

            return null;
        }

        /**
         * После завершения фоновой задачи закрываем прогрес диалог
         * **/
        protected void onPostExecute(String file_url) {
            // закрываем прогресс диалог после получение все продуктов
            pDialog.dismiss();
            // обновляем UI форму в фоновом потоке
            runOnUiThread(new Runnable() {
                public void run() {
                    /**
                     * Обновляем распарсенные JSON данные в ListView
                     * */
                    ListAdapter adapter = new SimpleAdapter(
                            AllPlacesActivity.this, productsList,
                            R.layout.place_item, new String[] { ID,
                            ADDRESS},
                            new int[] { R.id.ID, R.id.ADDRESS });
                    // обновляем listview
                    setListAdapter(adapter);
                }
            });

        }

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

        <LinearLayout
            style="@style/placeItem">
            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#eff3f3"/>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <TextView
                    android:id="@+id/ID" />
                <TextView
                    style="@style/placeName"
                    android:id="@+id/ADDRESS"
                    android:text="BUBBLE BOOM KENIGSBERG | 1км | Победы площадь 10 2 этаж, ТЦ Кловер" />
                <LinearLayout
                    style="@style/placeItemButton">
                    <ImageButton
                        style="@style/placeItemEnter"/>
                    <View
                        style="@style/placeButtonBorder"
                        />
                    <LinearLayout
                        style="@style/placeItemPeoples"
                        android:gravity="center">
                        <ImageButton
                            style="@style/placeItemPeoplesImg"/>
                        <TextView
                            style="@style/placeItemPeoplesTxt"
                            android:text="5"/>
                    </LinearLayout>
                </LinearLayout>
            </RelativeLayout>
            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#d5d8d8"/>
            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#e5e9e9"/>
        </LinearLayout>

</LinearLayout>
  • Вопрос задан
  • 109 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы