任何人都知道如何在每次點擊listview中的項目時顯示其他片段細節中的詳細信息項?以及如何設置它們?任何人都有這樣的例子嗎? 列表視圖中僅顯示: - 那抹,gambar1,TIPE,mainmuscle,othermuscle,阿拉特,評級細節片段我想表明: -Nama,gambar1,TIPE,mainmuscle,othermuscle,阿拉特,等級,deskripsi,gambar2,gambar3,gambar4如何在listview中顯示片段中的項目詳細信息點擊
這裏我的代碼:
Fragment.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();
}
}
你在找onitemclick? – Pomagranite
是的,itemonclick listview和打開詳細片段listview每個時間項目點擊 –
當你在片段中使用listview,對不對?然後在itemclick上,您可以顯示一個自定義對話框,其中包含要顯示的所有詳細信息。 –