出于某种原因,当我的片段中的listview
被加载时,它会在第一行被截断,但是在我的应用程序中的其他listfragments
中使用了相同的代码,这些都很好??? ..
这是我的xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#eeeeee">
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#eeeeee"
android:dividerHeight="8dp"
android:listSelector="@drawable/list_row_selector"
/>
</LinearLayout>
这里是片段类..我的错误在于适配器类,因为我在其他正在工作的片段中使用它。
public class TabTwoFragment extends ListFragment {
private static final String TAG = AccommodationFragment.class.getSimpleName();
// Movies json url
private static final String url = "http://api.mywebsite.com/json.php";
private ProgressDialog pDialog;
private List<Movie> movieList = new ArrayList<Movie>();
private ListView listView;
private CustomListAdapter adapter;
private View mheaderView;
//private TextView txtFragmentone;
public static TabTwoFragment newInstance() {
Bundle bundle = new Bundle();
TabTwoFragment fragment = new TabTwoFragment();
fragment.setArguments(bundle);
return fragment;
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.accommodation_fragment, container, false);
rootView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT ));
listView = (ListView) getActivity().findViewById(android.R.id.list);
adapter = new CustomListAdapter(getActivity(), movieList);
setListAdapter(adapter);
mheaderView = inflater.inflate(R.layout.list_header, null);
pDialog = new ProgressDialog(getActivity());
// Showing progress dialog before making http request
pDialog.setMessage("Loading...");
pDialog.show();
// Creating volley request obj
JsonArrayRequest movieReq = new JsonArrayRequest(url,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.d(TAG, response.toString());
hidePDialog();
// Parsing json
for (int i = 0; i < response.length(); i++) {
try {
JSONObject obj = response.getJSONObject(i);
Movie movie = new Movie();
movie.setTitle(obj.getString("title"));
movie.setThumbnailUrl(obj.getString("image"));
movie.seturl(obj.getString("url"));
/*movie.setRating(((Number) obj.get("rating"))
.doubleValue());*/
movie.setYear(obj.getString("releaseYear"));
// Genre is json array
JSONArray genreArry = obj.getJSONArray("genre");
ArrayList<String> genre = new ArrayList<String>();
for (int j = 0; j < genreArry.length(); j++) {
genre.add((String) genreArry.get(j));
}
movie.setGenre(genre);
// adding movie to movies array
movieList.add(movie);
} 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(movieReq);
return rootView;
}
@Override
public void onDestroy() {
super.onDestroy();
hidePDialog();
setListAdapter(null);
}
private void hidePDialog() {
if (pDialog != null) {
pDialog.dismiss();
pDialog = null;
}
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
/* if (mheaderView != null) listView.addHeaderView(mheaderView);*/
// Don't forget to now call setListAdapter()
this.setListAdapter(adapter);
setHasOptionsMenu(true);
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
Movie m= movieList.get(position);
String yourURL = m.geturl();
MyDetailFragment myDetailFragment = new MyDetailFragment();
Bundle args = new Bundle();
args.putString("YourKey", yourURL);
myDetailFragment.setArguments(args);
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, myDetailFragment).addToBackStack(null).commit();
}
我不知道为什么它会切断我的列表视图,我真的无法找到自己的解决方案....所以任何帮助都会很棒!