不要
*
-
@Date:2019/2/15 14:10
-
@Description:描述信息
*/
public class frag01 extends Fragment {private ListView listView;
String strURL = “https://www.apiopen.top/novelApi”;@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {View view = inflater.inflate(R.layout.frag01, container, false); listView = view.findViewById(R.id.listview); return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
new Thread() {
@Override
public void run() {
super.run();boolean isnNet = HttpUitl.isNetworkConnection(getActivity()); String s = ""; if (isnNet) { s = HttpUitl.requesString(strURL); } else { } Message message = new Message(); message.what = 0; message.obj = s; handler.sendMessage(message); } }.start();
}
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 0:
String s= (String) msg.obj;Gson gson=new Gson(); JsonBean jsonBean= gson.fromJson(s, JsonBean.class); ArrayList<JsonBean.DataBean> list= (ArrayList<JsonBean.DataBean>) jsonBean.getData(); listView.setAdapter(new Adapter(getActivity(),list)); break; } }
};
}