框架简易

基类 抽象方法 重写oncreate 返回布局的方法

setContentView(bujuid());  

侧拉的监听

kdr.setDrawerListener(new DrawerLayout.DrawerListener()
    kdr.openDrawer(Gravity.LEFT);
    kdr.closeDrawer(Gravity.LEFT);

封装网络工具类

  public  static  String getnet(String s){      
          try {
        URL url = new URL(s);      
   HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();     
      httpURLConnection.setRequestMethod("GET");
        int responseCode = httpURLConnection.getResponseCode();
          if (responseCode == 200) {
   InputStream inputStream = httpURLConnection.getInputStream();
   ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
            byte[] bytes = new byte[1024];             
              int len = 0;
      while ((len = inputStream.read(bytes)) != {                 
       stream.write(bytes, 0, len);          
          }
             stream.close();       
            inputStream.close();
         String json = stream.toString();           
              return json;
                }      
        } catch (Exception e)          
           {         
           e.printStackTrace();  
           }    
             return null; 
           }

Bundle bundle = new Bundle();
bundle.putInt(“i”,i);
chilefragment.setArguments(bundle);
int i = getArguments().getInt(“i”);
i%=3;
type+=i;
网络工具类

   public  static  boolean internet(Context context){
ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
     NetworkInfo info = conn.getActiveNetworkInfo();
         if (info!=null){
         return info.isAvailable();
         }
         return  false;
         }

PullToRefreshListView

//设置刷新的加载模式
 kpull.setMode(PullToRefreshBase.Mode.BOTH);
  监听
 kpull.setOnRefreshListener
 停止刷新的方法
 kpull.onRefreshComplete();
 默认展示最后一条
 kpull.setSelection(lista.size()-(data.size()-1));

数据库

  public Sql(Context context) {
          super(context, "bw.db", null, 1);
}
db.execSQL("create table student (title varchar(100), img varchar(100))");
Dao层
    public  Dao(Context context){
       Sql sql = new Sql(context);
            db = sql.getWritableDatabase();
   }

数据库存值
for (int i=0;i<data.size();i++){
    Bean.DataBean dataBean = data.get(i);
    ContentValues contentValues = new ContentValues();

    contentValues.put("title",dataBean.getNews_title());
    contentValues.put("img",dataBean.getPic_url());
    dao.insert("student",null,contentValues);
}
数据库取值
Cursor query = dao.query("student", null, null, null, null, null, null);
     if (query.moveToFirst()){
           do {
               String title = query.getString(query.getColumnIndex("title"));
               String img = query.getString(query.getColumnIndex("img"));
               listb.add(new Bean.DataBean(title,img));

           }while (query.moveToNext());
     }
     query.close();
     有需要继续走一遍适配器

使用ImageLoader

String path =Environment.getExternalStorageDirectory()+"/Pictures";
ImageLoaderConfiguration build = new ImageLoaderConfiguration.Builder(this)
      //缓存到sd      
   .diskCache(new UnlimitedDiskCache(new File( path)))
     .build(); //初始化
  ImageLoader.getInstance().init(build);

    适配器
      图片的设置    缓存   圆角    默认图
      DisplayImageOptions build = new DisplayImageOptions.Builder()
         .showImageForEmptyUri(R.mipmap.ic_launcher)//设置默认图片
      .showImageOnFail(R.mipmap.ic_launcher)
      .cacheInMemory(true)//设置内存缓存     
      .cacheOnDisk(true)//设置支持SD卡缓存
       .displayer(new RoundedBitmapDisplayer(50))//设置圆角 
       .build();

Xlistview
kxlist.setPullLoadEnable(true);
kxlist.setPullRefreshEnable(true);
监听
kxlist.setXListViewListener(new XlistView.IXListViewListener()
停止刷新的方法

kxlist.stopRefresh();

原生json解析存数据库
//遍历所有小的添加进大的
for (int i=0;i<data.length();i++){
jsonArray1.put(data.get(i));
}
//使用原生添值 先定义object 存字段 后存到array
JSONObject jsonObject = new JSONObject();
jsonObject.put(“img”,image); 第一个参数为字段名
之后 jsonArray2.put(jsonObject); 在走适配器

猜你喜欢

转载自blog.csdn.net/weixin_43882910/article/details/86520636