R
R
run1822017-01-06 19:07:09
Java
run182, 2017-01-06 19:07:09

How to choose to open a page with a post from a list (Android)?

I deduce through ListView the list of records, using request to the server. How to open the post detail page, where to pass the id for this?

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>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Tutukov, 2017-06-19
@mrusklon

Further himself
https://codepen.io/STutukov/pen/eRvBxa?editors=1010

R
Roman Misyura, 2017-06-19
@MindMinimal

https://simplex.com.ua/ - Section "Practices" - you can count the number of slides (it will be * from ) and write current-slide on the left

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question