android一些方法
来源:互联网 发布:python ggplot2 编辑:程序博客网 时间:2024/06/16 11:44
1 传递对象给fragment
bundle = new Bundle();
bundle.putInt(FacePageFragment.ARG_POSITION, position);
bundle.putSerializable(FacePageFragment.ARG_FACE_DATA,
data.get(data.keySet().toArray()[position]));fragment.setArguments(bundle);
fragment.setArguments(bundle);
2/*
* 这个是解压ZIP格式文件的方法
*
* @zipFileName:是传进来你要解压的文件路径,包括文件的名字;
*
* @outputDirectory:选择你要保存的路劲;
*/
public static void unzip(String zipFileName, String outputDirectory)
throws Exception {
ZipInputStream in = new ZipInputStream(new FileInputStream(zipFileName));
try {
ZipEntry z;
String name = "";
while ((z = in.getNextEntry()) != null) {
name = z.getName();
Log.d("unzip", "unzipping file: " + name);
if (z.isDirectory()) {
Log.d("unzip", name + "is a folder");
// get the folder name of the widget
name = name.substring(0, name.length() - 1);
File folder = new File(outputDirectory + File.separator
+ name);
folder.mkdirs();
Log.d("unzip", "mkdir " + outputDirectory + File.separator
+ name);
} else {
Log.d("unzip", name + "is a normal file");
File file = new File(outputDirectory + File.separator
+ name);
file.createNewFile();
// get the output stream of the file
FileOutputStream out = new FileOutputStream(file);
int ch;
byte[] buffer = new byte[1024];
// read (ch) bytes into buffer
while ((ch = in.read(buffer)) != -1) {
// write (ch) byte from buffer at the position 0
out.write(buffer, 0, ch);
out.flush();
}
out.close();
}
}
} catch (Exception e) {
// TODO: handle exception
} finally {
if (in != null) {
in.close();
}
}
}
注:压缩包要是zip格式
3 解析.json文件,里面是json格式的字符串
/**
* 解析图片
*
* @param context
* @param reelBean
* @return
*/
public static List<GifEmotionBean> parserBean(
Context context, String path) {
List<GifEmotionBean> profileImageBeans = new ArrayList<GifEmotionBean>();
BufferedReader reader = null;
if (path == null) {
return null;
}
InputStreamReader is = null;
try {
if (path.contains("assets")) {
String pathString = path.replace("assets/", "");
is = new InputStreamReader(context.getResources().getAssets()
.open(pathString));
reader = new BufferedReader(is);
} else {
File file = new File(path);
is = new InputStreamReader(new FileInputStream(file) , "GBK");
reader = new BufferedReader(is);
}
StringBuilder sb = new StringBuilder();
String line = null;
if (reader != null) {
while ((line = reader.readLine()) != null) {
sb.append(line + " ");
}
}
String json = sb.toString();
JSONArray array = new JSONArray(json);
for (int i = 0; i < array.length(); i++) {
JSONObject object = array.getJSONObject(i);
GifEmotionBean bean = new GifEmotionBean(object);
profileImageBeans.add(bean);
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (is != null) {
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return profileImageBeans;
}
返回的是json里面的一些数据,封装在bean里面
- android一些方法代码
- Android一些常用方法
- android一些方法
- Android一些工具方法
- Android 一些方法的触发
- android 一些数据转换方法
- Android 一些管理器的方法
- Android中的一些方法-----生生不息
- Android性能优化一些方法
- Android性能优化一些方法
- Android 一些鲜为人知的方法
- Android开发一些实用方法
- Android性能优化一些方法
- Android性能优化一些方法
- android 封装一些高效方法
- 安装android编辑环境的一些方法
- Android图片处理的的一些方法
- android view的一些常用触发方法
- Cg shader with refraction mapping
- 图像滤镜艺术---ZPhotoEngine超级算法库
- Listview的OnItemClick无反应
- spring详解:通过FactoryBean自定义工厂初始化Bean
- Android中handler的工作原理
- android一些方法
- HttpClient PostMethod提交自定义参数
- C#中System.Drawing来画立体饼状图
- 维度模型数据仓库(五) —— 定期装载
- Android 应用中设置图片高斯模糊
- KeyDown事件后
- maven resources plugin 2.5插件找不到
- 美团下拉刷新
- C++ Virtual详解