博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
week2
阅读量:5054 次
发布时间:2019-06-12

本文共 6720 字,大约阅读时间需要 22 分钟。

public class MainActivity extends AppCompatActivity implements XListView.IXListViewListener{    private XListView xlv;    private int page=1;    private boolean flag;    private MyBaseadapter adapter;    private List
list; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getSupportActionBar().hide();//隐藏应用名 xlv = (XListView) findViewById(R.id.xlv); xlv.setPullLoadEnable(true); xlv.setXListViewListener(this);//xlistview所需的方法 data(); } public void data(){
//url网址 jiexi("http://api.kkmh.com/v1/daily/comic_lists/1487606400?since=0&gender=0&sa_event=eyJwcm9qZWN0Ijoia3VhaWthbl9hcHAiLCJ0aW1lIjoxNDg3ODI5MDIzNDgxLCJwcm9wZXJ0aWVzIjp7IkhvbWVwYWdlVGFiTmFtZSI6IueDremXqCIsIlZDb21tdW5pdHlUYWJOYW1lIjoi54Ot6ZeoIiwiJG9%22%20+%22zX3ZlcnNpb24iOiI0LjIuMiIsIkdlbmRlclR5cGUiOiLlpbPniYgiLCJGcm9tSG9tZXBhZ2VUYWJOYW1lIjoi54Ot6ZeoIiwiJGxpYl92ZXJzaW9uIjoiMS42LjM0IiwiJG5ldHdvcmtfdHlwZSI6IldJRkkiLCIkd2lmaSI6dHJ1ZSwiJG1hbnVmYWN0dXJlciI6InNhbXN1bmciLCJGcm9tSG9tZXBhZ2VVcGRhdGVEYXRlIjoyLCIkc2NyZWVuX2hlaWdodCI6NTc2LCJIb21lcGFnZVVwZGF0ZURhdGUiOjEsIlByb3BlcnR5RXZlbnQiOiJSZWFkSG9tZVBhZ2UiLCJGaW5kVGFiTmFtZSI6IuaOqOiNkCIsImFidGVzdF9ncm91cCI6NDYsIiRzY3JlZW5fd2lkdGgiOjEwMjQsIiRvcyI6IkFuZHJvaWQiLCJUcmlnZ2VyUGFnZSI6IkhvbWVQYWdlIiwiJGNhcnJpZXIiOiJDTUNDIiwiJG1vZGVsIjoiR1QtUDUyMTAiLCIkYXBwX3ZlcnNpb24iOiIzLjguMSJ9LCJ0eXBlIjoidHJhY2siLCJkaXN0aW5jdF9pZCI6IkE6OTA1MTA0Mjc2Mzc1NTEwOSIsIm9yaWdpbmFsX2lkIjoiQTo5MDUxMDQyNzYzNzU1MTA5IiwiZXZlbnQiOiJSZWFkSG9tZVBhZ2UifQ%3D%3D"); } public void jiexi(String path){
//解析网址显示数据 new AsyncTask
(){
//使用异步的方法 @Override protected void onPostExecute(String s) { if (s!=null){ Gson gson=new Gson(); Bean bean = gson.fromJson(s, Bean.class); list = bean.getData().getComics(); if (adapter==null) { adapter = new MyBaseadapter(MainActivity.this, list); xlv.setAdapter(adapter); }else{ adapter.sss(list,flag); } xlv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView
adapterView, View view, int i, long l) { Intent intent=new Intent(MainActivity.this,Main2.class); intent.putExtra("url",list.get(i).getUrl());//传值 startActivity(intent); } }); } } @Override protected String doInBackground(String... params) { try { URL url=new URL(params[0]); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setReadTimeout(3000); connection.setConnectTimeout(3000); int code = connection.getResponseCode(); if (code==200){ InputStream is = connection.getInputStream(); return info.readFromNetWork(is); } } catch (Exception e) { e.printStackTrace(); } return null; } }.execute(path); } @Override public void onRefresh() {
//上啦刷新 flag=false; ++page; data(); xlv.stopRefresh(true); } @Override public void onLoadMore() {
//下拉加载 flag=true; ++page; data(); xlv.stopLoadMore(); }}
public class MyBaseadapter extends BaseAdapter {    private List
list; private Context context; public MyBaseadapter(Context context, List
list) { this.context=context; this.list=list; } public void sss(List
data,boolean flag){ for (Bean.DataBean.ComicsBean s: data) { if (flag){ list.add(s); }else{ list.add(0,s); } } notifyDataSetChanged(); } @Override public int getCount() { return list!=null?list.size():0; } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHoder hoder=null; if (convertView==null){ hoder=new ViewHoder(); convertView=View.inflate(context,R.layout.item,null); hoder.manhuaming= (TextView) convertView.findViewById(manhuaming); hoder.zuozhe= (TextView) convertView.findViewById(zuozhe); hoder.zhuangjie= (TextView) convertView.findViewById(zhuangjie); hoder.dianzan= (TextView) convertView.findViewById(dianzan); hoder.pinglun= (TextView) convertView.findViewById(pinglun); hoder.image= (ImageView) convertView.findViewById(R.id.image); convertView.setTag(hoder); }else{ hoder= (ViewHoder) convertView.getTag(); } hoder.manhuaming.setText(" "+list.get(position).getTopic().getTitle()); hoder.zuozhe.setText("作者:"+list.get(position).getTopic().getUser().getNickname()); hoder.zhuangjie.setText("最新章节:"+list.get(position).getTitle()); hoder.dianzan.setText("点赞: "+list.get(position).getLikes_count()); hoder.pinglun.setText("评论: "+list.get(position).getComments_count()); ImageLoader.getInstance().displayImage(list.get(position).getCover_image_url(),hoder.image,appliction.getImageOptions()); return convertView; }//listview优化 class ViewHoder{ private TextView manhuaming,zuozhe,zhuangjie,dianzan,pinglun; private ImageView image; }}
public class Main2 extends AppCompatActivity {    private WebView web;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity2);        getSupportActionBar().hide();        web = (WebView) findViewById(R.id.web);        Intent url=getIntent();        String s = url.getStringExtra("url");//接收传过来的值        web.loadUrl(s);//使用webview显示    }

 

转载于:https://www.cnblogs.com/leshen/p/7503646.html

你可能感兴趣的文章
BZOJ 2324 (有上下界的)费用流
查看>>
python3基础06(随机数的使用)
查看>>
Zookeeper系列(二)特征及应用场景
查看>>
【HTTP】Fiddler(三)- Fiddler命令行和HTTP断点调试
查看>>
Spring Boot使用Druid和监控配置
查看>>
poi 处理空单元格
查看>>
Android 内存泄漏优化总结
查看>>
luogu4849 寻找宝藏 (cdq分治+dp)
查看>>
Spring Cloud微服务笔记(五)Feign
查看>>
C语言键盘按键列表
查看>>
Codeforces Round #374 (Div. 2)
查看>>
oracle数据类型
查看>>
socket
查看>>
Vue中使用key的作用
查看>>
二叉索引树 树状数组
查看>>
日志框架--(一)基础篇
查看>>
Java设计模式之原型模式
查看>>
Spring学习(四)-----Spring Bean引用同xml和不同xml bean的例子
查看>>
哲理故事与管理之道(20)-用危机激励下属
查看>>
关于源程序到可运行程序的过程
查看>>