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;
@Override
public void onCreate(Bundle savedInstanceState)
{
/* try {
Thread.sleep(15000,0);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.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 页面转换
不知道做游戏的是怎么做的,现在只是知道了这么点皮毛而已。