ThreeQieHuan
来源:互联网 发布:linux mmap使用 编辑:程序博客网 时间:2024/06/15 22:25
public class ChildFragment1 extends Fragment{ private String titleUrl = "https://www.toutiao.com/hot_words/"; private ImageView iv; private TextView tv; ArrayList<String> titleList = new ArrayList<>(); int flag = 0; Handler handler = new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); int what = msg.what; if (what ==1 ){ if(titleList !=null){ int position = flag%titleList.size(); tv.setText(titleList.get(position)); } flag++; sendMsg(); } } }; //只写加载布局和找到控件 @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.tain, null); iv = view.findViewById(R.id.iv); tv = view.findViewById(R.id.tv); return view; } /** * 写fragment的逻辑; * @param view * @param savedInstanceState */ @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); initTitlData(); } /** * 获取头条内容数据 */ private void initTitlData() { new MTitleAsyncTask().execute(titleUrl); } private class MTitleAsyncTask extends AsyncTask<String,Void,String>{ @Override protected String doInBackground(String... strings) { String netJson = NetUtil.getNetJson(strings[0]); return netJson; } @Override protected void onPostExecute(String s) { super.onPostExecute(s); try { JSONArray jsonArray = new JSONArray(s); for (int i = 0; i < jsonArray.length(); i++) { Log.e("wzq", "onPostExecute: "+jsonArray.getString(i) ); titleList.add(jsonArray.getString(i)); } sendMsg(); } catch (JSONException e) { e.printStackTrace(); } } } private void sendMsg() { //延迟发送消息; handler.sendEmptyMessageDelayed(1,3000); }}
阅读全文
0 0
- ThreeQieHuan
- leetcode---longest-substring-without-repeating-characters---字符串
- linux——线程
- HTML5动画和鼠标移动
- TCP/IP 关于一些在应用层的协议
- 先码后看 Tomcat是怎么启动的?——Bootstrap引导 侵立删
- ThreeQieHuan
- -lrt问题,即:shm_open的头文件存在,编译却不通过,提示undefined
- 数据结构笔记(一)线性表的顺序表示和基本操作及其顺序表实现的集合运算(A-B)U(B-A)实例
- baidua
- 【2017.11.04】周末胡策题
- Default源代码
- 剑指offer——面试题9:菲波那切数列
- Rxjava简单理解记录
- Hibernate连接mysql数据库并自动创建表