这是ListView层
/**
* ListView设置
*/
public class MyListViewAdataper extends BaseAdapter{
private LayoutInflater mInflater;
List<Map<String,String>> temp;
public MyListViewAdataper(Context context,List<Map<String,String>> listview){
this.mInflater = LayoutInflater.from(context);
temp=listview;
}
public int getCount() {
// TODO Auto-generated method stub
return temp.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return temp.get(position);
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView==null){
HashMap<String,String> hashMap=(HashMap<String,String>)temp.get(position);
if(position<1){
convertView = mInflater.inflate(R.layout.adjoining_around, null);
LayoutInflater factory = LayoutInflater.from(AdjoiningActivity.this);
//获得自定义对话框
View view = factory.inflate(R.layout.edittext_item, null);
//昵称
TextView xingming= (TextView)convertView.findViewById(R.id.xingming);
xingming.setText(hashMap.get("name"));
//账号
TextView zhanghao=(TextView)convertView.findViewById(R.id.zhanghao);
zhanghao.setText(hashMap.get("number"));
//签名
TextView qianming=(TextView)convertView.findViewById(R.id.qianming);
qianming.setText(hashMap.get("qianming"));
}else{
convertView = mInflater.inflate(R.layout.friend_item, null);
//昵称
TextView xingming= (TextView)convertView.findViewById(R.id.xingming);
xingming.setText(hashMap.get("name"));
//账号
TextView zhanghao=(TextView)convertView.findViewById(R.id.zhanghao);
zhanghao.setText(hashMap.get("number"));
//签名
TextView qianming=(TextView)convertView.findViewById(R.id.qianming);
qianming.setText(hashMap.get("qianming"));
}
}
return convertView;
}
}
/**
* 点击listView
*/
private void listviewOnClick(){
listview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
String app=listviewAdataper.getItem(arg2).toString();
//跳转画面
Intent intent=new Intent(AdjoiningActivity.this,SpeakActivity.class);
SpeakActivity.retrunActivity=AdjoiningActivity.class;
//传递登录id
Bundle bundle=new Bundle();
bundle.putString("App", app);
bundle.putString("loginidid", idd);
intent.putExtras(bundle);
startActivity(intent);
AdjoiningActivity.this.finish();
}
});
}
这是onCreate层
pdialog=ProgressDialog.show(AdjoiningActivity.this, "请稍等片刻...", "正在获取好友列表...", true);
new Thread(){
public void run(){
try{
String list=adjoining.GPS();
if(list.length()>20){
JSONObject ject=new JSONObject(list);
String array=ject.getString("array");
JSONArray jsarray=new JSONArray(array);
for (int i = 0; i < jsarray.length(); i++) {
JSONObject jss=jsarray.getJSONObject(i);
//userid:用户id;name:用户昵称;image:头像;autoname:账号;spar:个性签名;coordinate:坐标
String id=jss.getString("userid");
String name=jss.getString("name");
String image=jss.getString("image");
String autoname=jss.getString("autoname");
String spar=jss.getString("spar");
String coordinate=jss.getString("coordinate");
map=new HashMap<String,String>();
map.put("userid",id);
map.put("name",name);
map.put("image",image);
map.put("autoname", autoname);
map.put("spar", spar);
map.put("coordinate", coordinate);
listmap.add(map);
}
}
handlerle.sendEmptyMessage(1);
}catch (ClientProtocolException ce) {
// TODO: handle exception
ce.printStackTrace();
handlerle.sendEmptyMessage(2);
}catch (IOException ioe) {
// TODO: handle exception
ioe.printStackTrace();
handlerle.sendEmptyMessage(2);
}catch (JSONException jsone) {
// TODO: handle exception
jsone.printStackTrace();
handlerle.sendEmptyMessage(2);
}
}
}.start();
以及
private Handler handlerle=new Handler(){
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub