我發現了非常類似的問題,但我沒有找到答案。我試圖阻止滑動滾動和我使用片段的選項卡活動。我正在使用這個https://github.com/johannilsson/android-pulltorefresh,但我得到一個錯誤getListview()它是說方法getListView()是未定義的類型Brottfarir我找到了解決方案,這使用擴展ListActivity,但因爲我擴展片段我不能做那。任何解決方案在android開發中使用片段和ListaActivity的問題
public class Brottfarir extends Fragment {
private static String url = "http://apis.is/flight?language=en&type=departures";
private static final String TAG_RESULTS = "results";
private JSONArray results = null;
public static ArrayList<Flight> resultsList;
private ListView listView;
private View rootView;
// gerum fligh object fyrir það sem er valið à lista og pos breytur sem heldur utan um position à listview.
private Flight flight;
private Integer pos=null;
private ListView listViewRefresh = null;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_brottfarir, container, false);
// not use this for now, create dummy data until this has been fixed
//new GetResults().execute();
resultsList = createDummyFlights();
MyArrayAdapter adapter = new MyArrayAdapter(getActivity(), resultsList);
// populate the listView
listView = (ListView)rootView.findViewById(R.id.list);
listView.setAdapter(adapter);
// listener for click
listView.setOnItemLongClickListener(onListClick);
// Set a listener to be invoked when the list should be refreshed.
((PullToRefreshListView) listView).setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh() {
// Do work to refresh the list here.
//new GetResults().execute();
resultsList = createDummyFlights();
}
});
return rootView;
}
這裏是我的XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#EE1616" >
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Brottfarir123"
android:textSize="20dp"
android:layout_centerInParent="true"/>
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#1a2421"
android:layout_weight="1"
android:drawSelectorOnTop="false"/>
發表您的XML佈局 – zozelfelfo