【问题标题】:How To Display Details item from listview [closed]如何从列表视图中显示详细信息项目[关闭]
【发布时间】:2016-05-03 04:01:47
【问题描述】:

当我每次从列表视图中单击项目时,任何人都知道如何在其他片段详细信息中显示详细信息项目?以及如何设置它们?有人有这方面的例子吗?

使用对话框或片段显示细节更好吗?

在列表视图中仅显示: - Nama,gambar1,tipe,mainmuscle,othermuscle,alat,详细评分片段我想展示: -Nama, gambar1, tipe, mainmuscle, othermuscle, alat, rating, deskripsi, gambar2, gambar3, gambar4

这里是我的代码:

片段.java

    public class AbdominalFragment extends Fragment {
    // Log tag
    private static final String TAG = AbdominalFragment.class.getSimpleName();

    // Movies json url
    private static final String url = "http.......";
    private ProgressDialog pDialog;
    private List<Exercise> exerciseList = new ArrayList<Exercise>();
    private ListView listView;
    private CustomListAdapter adapter;

    public AbdominalFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        hidePDialog();
    }

    private void hidePDialog() {
        if (pDialog != null) {
            pDialog.dismiss();
            pDialog = null;
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.activity_list, container, false);
        // Inflate the layout for this fragment

        final ListView listView = (ListView) rootView.findViewById(R.id.list);
        adapter = new CustomListAdapter(getActivity(), exerciseList);
        listView.setAdapter(adapter);

        pDialog = new ProgressDialog(getActivity());
        // Showing progress dialog before making http request
        pDialog.setMessage("Loading...");
        pDialog.show();

        if(exerciseList.isEmpty()) {
            // Creating volley request obj
            JsonArrayRequest exerciseReq = new JsonArrayRequest(url,
                    new Response.Listener<JSONArray>() {
                        @Override
                        public void onResponse(JSONArray response) {
                            Log.d(TAG, response.toString());
                            hidePDialog();

                            exerciseList.clear();

                            // Parsing json
                            for (int i = 0; i < response.length(); i++) {
                                try {

                                    JSONObject obj = response.getJSONObject(i);
                                    Exercise exercise = new Exercise();
                                    if (obj.getString("tipe").equals("abdominal")) {
                                        exercise.setNama(obj.getString("nama"));
                                        exercise.setGambar1(obj.getString("gambar1"));
                                        exercise.setTipe(obj.getString("tipe"));
                                        exercise.setMainmuscle(obj.getString("mainmuscle"));
                                        exercise.setAlat(obj.getString("alat"));
                                        exercise.setTipe(obj.getString("othermuscle"));
                                        exercise.setRating(obj.getDouble("rating"));


                                        // adding exercise to exercise array
                                        exerciseList.add(exercise);
                                    }
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }

                            }

                            // notifying list adapter about data changes
                            // so that it renders the list view with updated data
                            adapter.notifyDataSetChanged();
                        }
                    }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d(TAG, "Error: " + error.getMessage());
                    hidePDialog();

                }
            });

            // Adding request to request queue
            AppController.getInstance().addToRequestQueue(exerciseReq);
        }else{
            hidePDialog();
        }
        return rootView;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }
}

【问题讨论】:

  • 到底是什么问题? JSON 解析、传递数据或替换另一个片段或其他内容?
  • 抱歉,实际上我想知道当我从列表视图中单击一个带有详细信息的项目时如何显示显示项目
  • 你需要先google一下看看。无论如何,对于初学者来说,这应该会有所帮助...sunil-android.blogspot.in/2013/07/…
  • hmm 你的链接就像两个片段,但是当项目点击移动到另一个片段并获取详细项目时如何转换?就像我在第一篇文章中给出的图片一样

标签: android listview android-fragments


【解决方案1】:

当然片段更好,因为它们适应屏幕大小,例如,如果它的平板电脑,它将并排显示列表和详细信息,否则在手机中单击列表将显示详细信息屏幕。

例如,点击此链接。

http://mobileappdocs.com/android.html

【讨论】:

  • 谢谢,我想要这个来源,但是如何在我的代码上实现itemonclick,你能帮我吗?
  • 在上面的例子中也有。
  • 感谢 btw 已经看到但不知道我必须把代码放在哪里:D
猜你喜欢
  • 2011-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-06
  • 1970-01-01
相关资源
最近更新 更多