android项目文件简介 及JSON文件解析
来源:互联网 发布:scx4321驱动mac版 编辑:程序博客网 时间:2024/05/20 14:16
1 src
存放源文件的地方
2. gen
自动生成的文件
3 android 2.1 的库文件
4assets 存放外部文件的地方如json文件
4 res
里面有layout ,布局,控件可以画上去的那种
values定义标题名字的地方可以
AndroidManifest.xml 这个文件也很重要,在里面设置新的active的地方。
package com.android.ling;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.UnsupportedEncodingException;import java.util.Iterator;import java.util.LinkedList;import java.util.Map;import org.json.JSONArray;import org.json.JSONException;import org.json.JSONObject;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.View.OnClickListener;import android.widget.AdapterView;import android.widget.AdapterView.OnItemClickListener;import android.widget.ArrayAdapter;import android.widget.Button;import android.widget.ListAdapter;import android.widget.ListView;import android.widget.TextView;public class json extends Activity {private JSONObject dataJson=null;private JSONObject nbaJson=null;private String TAG="com.android.ling"; private ListView lv=null;private String str=new String();private String temp;private String [] result=null;private InputStream fil = null;private BufferedReader br=null;@Overridepublic void onCreate(Bundle savedInstanceState) { /* try {Thread.sleep(15000,0);} catch (InterruptedException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}*/ super.onCreate(savedInstanceState); setContentView(R.layout.index); try{ fil = getAssets().open("list.json"); }catch(IOException e){ e.printStackTrace(); Log.d(TAG,"=========="+fil); } try{ br=new BufferedReader(new InputStreamReader(fil,"UTF-8")); }catch (UnsupportedEncodingException e) { e.printStackTrace(); Log.d(TAG,"=========="+br); } try{ while(br!=null&&null!=(temp=br.readLine())) { str+=temp; if(null!=str) Log.d(TAG,"str is =========="+str); } }catch(IOException e){ e.printStackTrace(); Log.d(TAG,"=========="+str); } try{ dataJson = new JSONObject(str); if(null!=dataJson) Log.d(TAG,"datajson is=========="+dataJson); }catch (JSONException e){ e.printStackTrace(); Log.d(TAG," datajson is =========="+dataJson); } JSONArray js= dataJson.names(); result=new String[js.length()]; for(int i =0;i<js.length();i++) { result[i]=js.optString(i);//解析JSON文件, } lv=(ListView)findViewById(R.id.listView); ListAdapter adapter=new ArrayAdapter<String>( this,android.R.layout.simple_list_item_1 , result); lv.setAdapter(adapter); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { String map = arg0.getItemAtPosition(arg2).toString(); Intent i = new Intent(); i.setClass(json.this, json1.class); Bundle bundle=new Bundle(); bundle.putString("KEY_TEXT", map); bundle.putString("KEY_Object", str); //向另一个active传值 i.putExtras(bundle); startActivity(i); } } ); }}
package com.android.ling;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.UnsupportedEncodingException;import java.util.Iterator;import java.util.LinkedList;import org.json.JSONArray;import org.json.JSONException;import org.json.JSONObject;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.util.Log;import android.view.View;import android.widget.AdapterView;import android.widget.ArrayAdapter;import android.widget.ListAdapter;import android.widget.ListView;import android.widget.TextView;import android.widget.AdapterView.OnItemClickListener;public class json1 extends Activity {private ListView lv=null;private String TAG="com.android.ling"; private JSONObject dataJson=null;private JSONObject nbaJson=null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); try{ lv=(ListView)findViewById(R.id.listView1); Bundle bundle = this.getIntent().getExtras(); String text = bundle.getString("KEY_TEXT"); String str = bundle.getString("KEY_Object"); dataJson = new JSONObject(str); if(null!=dataJson) Log.d(TAG,"datajson is =========="+dataJson); nbaJson = dataJson.getJSONObject(text); JSONArray js=nbaJson.names(); String[] result=new String[js.length()]; for(int i=0;i<js.length();i++) { result[i]=js.optString(i); String value=nbaJson.optString(result[i]); result[i]=result[i]+" is "+ value; } ListAdapter adapter=new ArrayAdapter<String>( this,android.R.layout.simple_list_item_1 , result); lv.setAdapter(adapter); }catch (JSONException e){ e.printStackTrace(); Log.d(TAG," nba is=========="+nbaJson); }
使用了listview的控件
使用了intent 页面转换
不知道做游戏的是怎么做的,现在只是知道了这么点皮毛而已。
- android项目文件简介 及JSON文件解析
- android项目文件简介 及JSON文件解析
- Android中XML文件解析、系列化及JSON解析
- Android 中 JSON 及 XML 文件的解析
- Android下Json文件解析
- Android项目各个文件简介
- Android学习 (十六) JSON文件简介
- XML文件和JSON文件的解析及生成
- Android 解析assets中json文件
- Android 基础 android项目文件简介
- Android中的Xml文件与解析简介
- xml文件解析类及Android项目中常用到的两种获取xml文件方式
- JSON库解析json文件
- Json解析本地json文件
- JSon文件解析
- ajax解析json文件
- 转:解析json文件
- JSon文件解析
- HDU 3594 Cactus 图的强联通 tarjan
- java核心技术之 ArrayList应用 【职员薪水管理系统】
- 线程同步
- 突然想起还有这个博客
- ThreadLocal实现线程范围内的数据共享
- android项目文件简介 及JSON文件解析
- NHinernate查询总结
- PAINTSTRUCT结构
- 线程并发库----Executors
- C# 数据源生成多级xml
- 一种常见的数据挖掘的算法SPRINT算法的简单实现
- (2011.07.10-2011.07.15)六天的学习小记
- jsp 网站开发环境配置
- Linux 的学习,vim的使用