解析添加数据库
来源:互联网 发布:南风知我意txt 编辑:程序博客网 时间:2024/06/05 20:43
package com.example.lianxi_yue;import android.content.Context;import android.content.DialogInterface;import android.content.Intent;import android.net.ConnectivityManager;import android.net.NetworkInfo;import android.os.AsyncTask;import android.support.v7.app.AlertDialog;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.widget.ListView;import android.widget.Toast;import com.google.gson.Gson;import java.io.InputStream;import java.net.HttpURLConnection;import java.net.URL;import java.util.List;import static android.R.id.content;import static android.R.id.list;public class MainActivity extends AppCompatActivity { private Caozuo caozuo; private ListView lv; //判断网络 private boolean chexkNet(){ ConnectivityManager conn= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = conn.getActiveNetworkInfo(); if(info!=null&&info.isConnected()){ return true; } return false; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); lv = (ListView) findViewById(R.id.lv); caozuo = new Caozuo(MainActivity.this); //判断网络 boolean b=chexkNet(); if(!b){ //适配器 Youhua2 youhua2 = new Youhua2(MainActivity.this,caozuo.chaxunquan()); lv.setAdapter(youhua2); AlertDialog.Builder builder=new AlertDialog.Builder(this); builder.setMessage("去设置"); builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this,"去设置网络",Toast.LENGTH_SHORT).show(); Intent it=new Intent("android.settings.WIRELESS_SETTINGS"); startActivity(it); return; } }); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this,"查看本地",Toast.LENGTH_SHORT).show(); } }); builder.create(); builder.show(); } else{ Toast.makeText(MainActivity.this,"网络连接",Toast.LENGTH_SHORT).show();; getdata("http://v.juhe.cn/toutiao/index?type=%22%20+%20android.R.attr.name%20+%20%22&key=54e3d5f4ee64f51bef570ce8505d37b5"); } //操作数据库// String chaxunquan = caozuo.chaxunquan();//// Toast.makeText(MainActivity.this,"==="+chaxunquan,Toast.LENGTH_SHORT).show(); } public void getdata(final String data){ new AsyncTask<String,Void,String>(){ @Override protected void onPostExecute(String s) { super.onPostExecute(s); Gson gson = new Gson(); Bean bean = gson.fromJson(s, Bean.class); //String list = bean.getResult().getData().get(0).getTitle(); List<Bean.ResultBean.DataBean> data1 = bean.getResult().getData(); for (Bean.ResultBean.DataBean dataBean : data1) { caozuo.tianjia(dataBean.getTitle()); } //适配器 Youhua youhua = new Youhua(MainActivity.this,data1); lv.setAdapter(youhua); //添加数据库 System.out.println("============="+ android.R.id.list); } @Override protected String doInBackground(String... strings) { String url = strings[0]; try { HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.setRequestMethod("GET"); connection.setConnectTimeout(5000); connection.setReadTimeout(5000); int code = connection.getResponseCode(); if (code==200){ InputStream is = connection.getInputStream(); String shuju = Jiexi.shuju(is); return shuju; } } catch (Exception e) { e.printStackTrace(); } return null; } }.execute(data); }}
阅读全文
0 0
- 解析添加数据库
- 解析网络数据添加数据库
- Pull解析, 并添加到数据库中
- php解析网页并将数据添加到数据库
- DOM解析XML文件并添加到数据库中
- 添加数据库
- 添加数据库
- 数据库解析
- 深入解析python版SVM源码系列(一)——添加数据库和绘制效果图
- AsynTask异步任务+HttpURLConnection网络请求+Gson解析数据+添加到sqlite数据库展示数据
- 如何读取sd下的json文件,并解析展示,添加到数据库中
- 使用ImageLoader从网上获取图片 及添加数据库,listview展示 Gson解析
- json数据解析获取全国城市并且添加到数据库中(mavean、城市接口)
- Apach添加php解析
- VS2015如何添加解析
- 数据库添加帐号,添加用户
- mysql中添加数据库
- 数据库添加---图片变化
- Windows下用Composer安装Laravel步骤(集成php环境用phpStudy2016版本)
- 机器学习(绘图)
- 试试看
- URI和URL的区别
- 常用配置
- 解析添加数据库
- [ E10857-01]Oracle® Database Quick Installation Guide 11g Release 2 (11.2) for Linux x86
- 推送
- 友盟QQ整合配置文档
- android 自定义对话框
- Deep Learning论文笔记之(七)深度网络高层特征可视化
- POJ 1655 树的重心 解题报告
- 指定纹理glTexImage2D、GLUtils.texImage2D
- 杨辉三角按行输出--python