1. 程式人生 > >完美 解決fragment中listview資料丟失問題和問題分析

完美 解決fragment中listview資料丟失問題和問題分析

public class MainpageFind extends Fragment  {     private ListViewForScrollView mListview;     private FindShareAdatpter shareAdatpter = null;     private List<TaskFindInfo> tastlistdata=null;     @Override     public void onActivityCreated(@Nullable Bundle savedInstanceState) {         super.onActivityCreated(savedInstanceState);         if ( mListview.getAdapter()==null) {             if (shareAdatpter==null) {                 shareAdatpter = new FindShareAdatpter(getActivity());                 new HttpRest(getActivity(), mhandler, 1).get_findActivityList();//網路請求載入資料             }else{                 showlist(tastlistdata);             }         }     }     private Handler mhandler = new Handler(Looper.getMainLooper()) {         @Override         public void handleMessage(Message msg) {             if (msg.what == 1) {                 List<TaskFindInfo> taskinfos = (List<TaskFindInfo>) msg.obj;                 tastlistdata=taskinfos;                 showlist(taskinfos);             }         }     };     private void showlist(List<TaskFindInfo> tastlist) {         shareAdatpter.SetList(tastlist);         mListview.setAdapter(shareAdatpter);         shareAdatpter.notifyDataSetChanged();     }     @Override     public View onCreateView(LayoutInflater inflater, ViewGroup container,                              Bundle savedInstanceState) {         View view = inflater.inflate(R.layout.mainpage3, null);         bbstv = (TextView) view.findViewById(R.id.bbstv);         helptv = (TextView) view.findViewById(R.id.helptv);         helptv.setOnClickListener(this);         bbstv.setOnClickListener(this);         mListview = view.findViewById(R.id.actionlist);         return view;     } }