判斷是否有網 沒有從資料庫中取值
阿新 • • 發佈:2018-12-08
判斷是否有網 沒有從資料庫中取值
public class Frag02 extends Fragment { private ArrayList<JsonBean.DataBean> list = new ArrayList<JsonBean.DataBean>(); private Dao dao; private ListView ListView; private MyListAdapter adapter; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view1 = inflater.inflate(R.layout.frag02,container,false); dao = new Dao(getActivity()); ListView = view1.findViewById(R.id.listView); if (!MyNewWork.isConn(getActivity())){ Cursor query = dao.query("aaa", null, null, null, null, null, null, null); if (query.moveToFirst()) { do { String ssss = query.getString(query.getColumnIndex("name")); String pass = query.getString(query.getColumnIndex("pass")); list.add(new JsonBean.DataBean("","",ssss,pass)); }while (query.moveToNext()); } query.close(); }else{ Toast.makeText(getActivity(),"有網路",Toast.LENGTH_LONG).show(); } adapter = new MyListAdapter(getActivity(), list); ListView.setAdapter(adapter); return view1; } }
判斷有沒有網
有:MyNewWork.isConn(getActivity())
沒有:!MyNewWork.isConn(getActivity())
if (!MyNewWork.isConn(getActivity())){
}else{
Toast.makeText(getActivity(),"有網路",Toast.LENGTH_LONG).show();
}