主要实现的功能:就是将Jsonj解析后,显示在ListV iew控件上(包括网络取图片)

Json:

{"resultCode":1,"resultInfo":"SUCCESS","info":{"pageInfo":{"total":28,"pageSize":10,"lastPageNumber":3,"nowPage":1,"currNum":10},"merchantKey":[{"merchantID":"5327","name":"瑞庭竹岛酒店","coupon":"网上预定入住可享返现优惠","location":"四川省成都市高新区老成仁路8号","distance":"203m","picUrl":"http://www.warmtel.com/igme_pic/fe3e79c1f349474b98f06477bbdc009f.jpg","couponType":"YES","cardType":"NO","groupType":"NO","gpsX":104.079935,"gpsY":30.54066,"goodSayNum":0,"midSayNum":0,"badSayNum":0},{"merchantID":"2845","name":"目咖啡软件园C6店","coupon":"凭QQ美食享咖啡8折优惠","location":"四川省成都市高新区天华二路219号天府软件园C区6号楼1楼","distance":"479m","picUrl":"http://www.warmtel.com/igme_pic/33f7ab6e385143f097527d4507cabcbe.jpg","couponType":"YES","cardType":"NO","groupType":"NO","gpsX":104.078242,"gpsY":30.545434,"goodSayNum":0,"midSayNum":0,"badSayNum":0},{"merchantID":"5326","name":"九点国际酒店","coupon":"网上预定成功入住可返现金","location":"四川省成都市天府大道南段1号齐盛艺境[近世纪城会展中心]","distance":"556m","picUrl":"http://www.warmtel.com/igme_pic/c5721d159e63482b8a1d4dd9f70f9a03.jpg","couponType":"YES","cardType":"NO","groupType":"NO","gpsX":104.077416,"gpsY":30.53835,"goodSayNum":1,"midSayNum":0,"badSayNum":0},{"merchantID":"2841","name":"布衣客栈软件园店","coupon":"酒店消费券预订酒店返现金","location":"四川省成都市高新区世纪城南路399号[近天府软件园C区]","distance":"660m","picUrl":"http://www.warmtel.com/igme_pic/f8dc2d69a7b742eba4408bb72e510f5d.jpg","couponType":"YES","cardType":"YES","groupType":"NO","gpsX":104.080515,"gpsY":30.547937,"goodSayNum":0,"midSayNum":0,"badSayNum":0},{"merchantID":"11798","name":"茅台贵州液专卖店","coupon":"购买茅台红酒3件以上再送1件","location":"四川省成都市高新区中和镇姐儿堰路14号","distance":"683m","picUrl":"http://www.warmtel.com/igme_pic/df0a55009cea4b8ba2773278ffb3ff79.jpg","couponType":"NO","cardType":"NO","groupType":"NO","gpsX":104.079227,"gpsY":30.536175,"goodSayNum":0,"midSayNum":0,"badSayNum":0},{"merchantID":"2842","name":"巴国布衣软件园店","coupon":"持光大银行信用卡享成都巴国布衣8.8折优惠,截止2012-12-31.","location":"四川省成都市高新区世纪城南路399号","distance":"683m","picUrl":"http://www.warmtel.com/igme_pic/1f4781f9329b40218544fd4b7ec673c9.jpg","couponType":"NO","cardType":"YES","groupType":"NO","gpsX":104.080254,"gpsY":30.548117,"goodSayNum":0,"midSayNum":0,"badSayNum":0},{"merchantID":"5325","name":"香妃儿美容美体","coupon":"38元享980元超值美胸丰胸套餐","location":"四川省成都市高新区远大都市风景二期二号","distance":"703m","picUrl":"http://www.warmtel.com/igme_pic/26cfa2c850dd40cf9518d71ea55b687b.jpg","couponType":"NO","cardType":"NO","groupType":"NO","gpsX":104.080344,"gpsY":30.535779,"goodSayNum":0,"midSayNum":0,"badSayNum":0},{"merchantID":"3718","name":"锦咖啡","coupon":"凭锦咖啡折扣券可享餐品8.5折,饮品7.5折,牛排6.8折优惠.\r\n\r\n1.该优惠有效期:截止至2012年12月31日;\r\n2.凭此券可以享受以下优惠:\r\n餐品8.5折\r\n饮品7.5折\r\n牛排6.8折\r\n(营业时间:09:30-23:30)\r\n\r\n展示此页即享优惠.","location":"四川省成都市高新区天华路447-1号[近天府软件园B区]","distance":"874m","picUrl":"http://www.warmtel.com/igme_pic/7629ff4f8beb43d1bd0967baba46f6c6.jpg","couponType":"YES","cardType":"YES","groupType":"NO","gpsX":104.078756,"gpsY":30.549577,"goodSayNum":3,"midSayNum":0,"badSayNum":0},{"merchantID":"2416","name":"蜀国飘香远大店","coupon":"享菜品8.8折优惠(酒水除外)","location":"四川省成都市高新区远大都市风景商业街3号楼","distance":"1041m","picUrl":"http://www.warmtel.com/igme_pic/8f0e793995084f76a59cc789fb6f6c7e.jpg","couponType":"NO","cardType":"NO","groupType":"NO","gpsX":104.077334,"gpsY":30.533345,"goodSayNum":0,"midSayNum":0,"badSayNum":0},{"merchantID":"3719","name":"华庭茶府","coupon":"100元享120元小包优惠","location":"四川省成都市高新区天华路329号附1号[近天府软件园B区]","distance":"1057m","picUrl":"http://www.warmtel.com/igme_pic/1eeae0d361f54124bdd3b6600dcc6074.jpg","couponType":"YES","cardType":"YES","groupType":"NO","gpsX":104.078705,"gpsY":30.551274,"goodSayNum":0,"midSayNum":0,"badSayNum":0}]}}
可以看到上面的很乱,所以要用一个Json工具视图查看,这样就可以清楚的看出层次结构,现在看看具体的代码实现:
---------------------------------------------------<span style="font-family: Arial, Helvetica, sans-serif;">第一步</span>-----------------------------------------------------------------------------------------------

首先我们从最里面开始向外面一次写:
<pre name="code" class="html">package com.example.jsonlistview;

public class Totel {
	private String merchantID;
	private String name;
	private String coupon;
	private String location;
	private String distance;
	private String picUrl;
	private String couponType;
	private String cardType;
	private String groupType;
	private String gpsX;
	private String gpsY;
	private String goodSayNum;
	private String midSayNum;
	private String badSayNum;
	public String getMerchantID() {
		return merchantID;
	}
	public void setMerchantID(String merchantID) {
		this.merchantID = merchantID;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getCoupon() {
		return coupon;
	}
	public void setCoupon(String coupon) {
		this.coupon = coupon;
	}
	public String getLocation() {
		return location;
	}
	public void setLocation(String location) {
		this.location = location;
	}
	public String getDistance() {
		return distance;
	}
	public void setDistance(String distance) {
		this.distance = distance;
	}
	public String getPicUrl() {
		return picUrl;
	}
	public void setPicUrl(String picUrl) {
		this.picUrl = picUrl;
	}
	public String getCouponType() {
		return couponType;
	}
	public void setCouponType(String couponType) {
		this.couponType = couponType;
	}
	public String getCardType() {
		return cardType;
	}
	public void setCardType(String cardType) {
		this.cardType = cardType;
	}
	public String getGroupType() {
		return groupType;
	}
	public void setGroupType(String groupType) {
		this.groupType = groupType;
	}
	public String getGpsX() {
		return gpsX;
	}
	public void setGpsX(String gpsX) {
		this.gpsX = gpsX;
	}
	public String getGpsY() {
		return gpsY;
	}
	public void setGpsY(String gpsY) {
		this.gpsY = gpsY;
	}
	public String getGoodSayNum() {
		return goodSayNum;
	}
	public void setGoodSayNum(String goodSayNum) {
		this.goodSayNum = goodSayNum;
	}
	public String getMidSayNum() {
		return midSayNum;
	}
	public void setMidSayNum(String midSayNum) {
		this.midSayNum = midSayNum;
	}
	public String getBadSayNum() {
		return badSayNum;
	}
	public void setBadSayNum(String badSayNum) {
		this.badSayNum = badSayNum;
	}

	
}


 
------------------------------------------------------第二步----------------------------------------------------------------------------------------
package com.example.jsonlistview;


public class Pageinfo {


<span style="white-space:pre">	</span>private int total;
<span style="white-space:pre">	</span>private int pageSize;
<span style="white-space:pre">	</span>private int lastPageNumber;
<span style="white-space:pre">	</span>private int nowPage;
<span style="white-space:pre">	</span>private int currNum;


<span style="white-space:pre">	</span>public int getTotal() {
<span style="white-space:pre">		</span>return total;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void setTotal(int total) {
<span style="white-space:pre">		</span>this.total = total;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public int getPageSize() {
<span style="white-space:pre">		</span>return pageSize;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void setPageSize(int pageSize) {
<span style="white-space:pre">		</span>this.pageSize = pageSize;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public int getLastPageNumber() {
<span style="white-space:pre">		</span>return lastPageNumber;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void setLastPageNumber(int lastPageNumber) {
<span style="white-space:pre">		</span>this.lastPageNumber = lastPageNumber;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public int getNowPage() {
<span style="white-space:pre">		</span>return nowPage;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void setNowPage(int nowPage) {
<span style="white-space:pre">		</span>this.nowPage = nowPage;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public int getCurrNum() {
<span style="white-space:pre">		</span>return currNum;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void setCurrNum(int currNum) {
<span style="white-space:pre">		</span>this.currNum = currNum;
<span style="white-space:pre">	</span>}


}、
-----------------------------------------------------------------第三步---------------------------------------------------------------------------------
package com.example.jsonlistview;


public class Json {
<span style="white-space:pre">	</span>private String resultCode;
<span style="white-space:pre">	</span>private String resultInfo;
<span style="white-space:pre">	</span>private InFo info;


<span style="white-space:pre">	</span>public String getResultCode() {
<span style="white-space:pre">		</span>return resultCode;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void setResultCode(String resultCode) {
<span style="white-space:pre">		</span>this.resultCode = resultCode;
<span style="white-space:pre">	</span>}




<span style="white-space:pre">	</span>public String getResultInfo() {
<span style="white-space:pre">		</span>return resultInfo;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void setResultInfo(String resultInfo) {
<span style="white-space:pre">		</span>this.resultInfo = resultInfo;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public InFo getInfo() {
<span style="white-space:pre">		</span>return info;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void setInfo(InFo info) {
<span style="white-space:pre">		</span>this.info = info;
<span style="white-space:pre">	</span>}


}
=----------------------------------------------------------第四步写适配器-------------------------------------------------------------------------
package com.example.jsonlistview;


import java.util.ArrayList;
import java.util.List;


import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.squareup.picasso.Picasso;


public class Myadapters extends BaseAdapter {
<span style="white-space:pre">	</span>private List<UserBean> mList = new ArrayList<UserBean>();
<span style="white-space:pre">	</span>private LayoutInflater mInflater;
<span style="white-space:pre">	</span>private Context mcontext;


<span style="white-space:pre">	</span>public Myadapters(Context context) {
<span style="white-space:pre">		</span>mcontext = context;
<span style="white-space:pre">		</span>mInflater = LayoutInflater.from(mcontext);


<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void setData(List<UserBean> list) {
<span style="white-space:pre">		</span>this.mList = list;
<span style="white-space:pre">		</span>notifyDataSetChanged();
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>@Override
<span style="white-space:pre">	</span>public int getCount() {
<span style="white-space:pre">		</span>// TODO Auto-generated method stub
<span style="white-space:pre">		</span>return mList.size();


<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>@Override
<span style="white-space:pre">	</span>public Object getItem(int position) {
<span style="white-space:pre">		</span>return mList.get(position);
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>@Override
<span style="white-space:pre">	</span>public long getItemId(int position) {
<span style="white-space:pre">		</span>return position;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public View getView1(int position, View convertView, ViewGroup parent) {
<span style="white-space:pre">		</span>// TODO Auto-generated method stub
<span style="white-space:pre">		</span>return null;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>@Override
<span style="white-space:pre">	</span>public View getView(int position, View convertView, ViewGroup parent) {
<span style="white-space:pre">		</span>Log.e("aa", "dasdasda");
<span style="white-space:pre">		</span>ViewHolder holder;
<span style="white-space:pre">		</span>if (convertView == null) {
<span style="white-space:pre">			</span>holder = new ViewHolder();


<span style="white-space:pre">			</span>convertView = mInflater.inflate(R.layout.listvtxtv, null);


<span style="white-space:pre">			</span>holder.titleTxt = (TextView) convertView
<span style="white-space:pre">					</span>.findViewById(R.id.listtex1);
<span style="white-space:pre">			</span>holder.neirongTxt = (TextView) convertView
<span style="white-space:pre">					</span>.findViewById(R.id.listtex2);
<span style="white-space:pre">			</span>holder.infoTxt = (TextView) convertView.findViewById(R.id.listtex3);
<span style="white-space:pre">			</span>holder.infoTxt1 = (TextView) convertView
<span style="white-space:pre">					</span>.findViewById(R.id.listtex31);
<span style="white-space:pre">			</span>holder.imageView = (ImageView) convertView.findViewById(R.id.imgs);
<span style="white-space:pre">			</span>convertView.setTag(holder);
<span style="white-space:pre">		</span>} else {
<span style="white-space:pre">			</span>holder = (ViewHolder) convertView.getTag();
<span style="white-space:pre">		</span>}


<span style="white-space:pre">		</span>holder.neirongTxt.setText(mList.get(position).getName());
<span style="white-space:pre">		</span>holder.titleTxt.setText(mList.get(position).getCoupon());
<span style="white-space:pre">		</span>holder.infoTxt.setText(mList.get(position).getDistance());
<span style="white-space:pre">		</span>holder.infoTxt1.setText(mList.get(position).getLocation());
//用Picasso进行网络取图片
<span style="white-space:pre">		</span>Picasso.with(mcontext).load(mList.get(position).getPicUrl())
<span style="white-space:pre">				</span>.into(holder.imageView);
<span style="white-space:pre">		</span>return convertView;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>class ViewHolder {


<span style="white-space:pre">		</span>ImageView imageView = null;
<span style="white-space:pre">		</span>TextView titleTxt = null;
<span style="white-space:pre">		</span>TextView neirongTxt = null;
<span style="white-space:pre">		</span>TextView infoTxt = null;
<span style="white-space:pre">		</span>TextView infoTxt1 = null;
<span style="white-space:pre">	</span>}


}
--------------------------------------------------------------第五步把json里边需要显示的属性单写出来------------------------------------------------------
package com.example.jsonlistview;


public class UserBean {
<span style="white-space:pre">	</span>private String name;
<span style="white-space:pre">	</span>private String coupon;
<span style="white-space:pre">	</span>private String location;
<span style="white-space:pre">	</span>private String distance;
<span style="white-space:pre">	</span>private String picUrl;
<span style="white-space:pre">	</span>
<span style="white-space:pre">	</span>private String couponType;
<span style="white-space:pre">	</span>private String cardType;
<span style="white-space:pre">	</span>private String groupType;
<span style="white-space:pre">	</span>
<span style="white-space:pre">	</span>public String getName() {
<span style="white-space:pre">		</span>return name;
<span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>public void setName(String name) {
<span style="white-space:pre">		</span>this.name = name;
<span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>public String getCoupon() {
<span style="white-space:pre">		</span>return coupon;
<span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>public void setCoupon(String coupon) {
<span style="white-space:pre">		</span>this.coupon = coupon;
<span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>public String getLocation() {
<span style="white-space:pre">		</span>return location;
<span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>public void setLocation(String location) {
<span style="white-space:pre">		</span>this.location = location;
<span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>public String getDistance() {
<span style="white-space:pre">		</span>return distance;
<span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>public void setDistance(String distance) {
<span style="white-space:pre">		</span>this.distance = distance;
<span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>public String getPicUrl() {
<span style="white-space:pre">		</span>return picUrl;
<span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>public void setPicUrl(String picUrl) {
<span style="white-space:pre">		</span>this.picUrl = picUrl;
<span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>public String getCouponType() {
<span style="white-space:pre">		</span>return couponType;
<span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>public void setCouponType(String couponType) {
<span style="white-space:pre">		</span>this.couponType = couponType;
<span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>public String getCardType() {
<span style="white-space:pre">		</span>return cardType;
<span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>public void setCardType(String cardType) {
<span style="white-space:pre">		</span>this.cardType = cardType;
<span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>public String getGroupType() {
<span style="white-space:pre">		</span>return groupType;
<span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>public void setGroupType(String groupType) {
<span style="white-space:pre">		</span>this.groupType = groupType;
<span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>
          
}
-------------------------------------------------------第六步在主Activyi里面写异步(网络取数据)及添加json属性--------------------------------------------
package com.example.jsonlistview;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;


import com.google.gson.Gson;


import android.app.Activity;
import android.database.MergeCursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.widget.ListView;


public class JsonActivity extends Activity {
<span style="white-space:pre">	</span>String http = "http://192.168.1.127:8080/json/around";


<span style="white-space:pre">	</span>private ListView mListView;
<span style="white-space:pre">	</span>private Myadapters myadapters;


<span style="white-space:pre">	</span>@Override
<span style="white-space:pre">	</span>protected void onCreate(Bundle savedInstanceState) {
<span style="white-space:pre">		</span>super.onCreate(savedInstanceState);
<span style="white-space:pre">		</span>requestWindowFeature(Window.FEATURE_NO_TITLE);
<span style="white-space:pre">		</span>setContentView(R.layout.activity_json);


<span style="white-space:pre">		</span>mListView = (ListView) findViewById(R.id.totellistview);
<span style="white-space:pre">		</span>myadapters = new Myadapters(this);
<span style="white-space:pre">		</span>mListView.setAdapter(myadapters);
<span style="white-space:pre">		</span>new AsyncTask<String, Void, List<UserBean>>() {


<span style="white-space:pre">			</span>@Override
<span style="white-space:pre">			</span>protected List<UserBean> doInBackground(String... params) {
<span style="white-space:pre">				</span>// TODO Auto-generated method stub
<span style="white-space:pre">				</span>return getData();
<span style="white-space:pre">			</span>}


<span style="white-space:pre">			</span>@Override
<span style="white-space:pre">			</span>protected void onPostExecute(List<UserBean> result) {
<span style="white-space:pre">				</span>// TODO Auto-generated method stub
<span style="white-space:pre">				</span>Log.e("result", result + "");
<span style="white-space:pre">				</span>myadapters.setData(result);
<span style="white-space:pre">			</span>}
<span style="white-space:pre">		</span>}.execute();


<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>private List<UserBean> getData() {
<span style="white-space:pre">		</span>URL url = null;
<span style="white-space:pre">		</span>InputStream is = null;
<span style="white-space:pre">		</span>List<UserBean> mlist = new ArrayList<UserBean>();
<span style="white-space:pre">		</span>StringBuffer sb = new StringBuffer();
<span style="white-space:pre">		</span>BufferedReader br = null;
<span style="white-space:pre">		</span>try {
<span style="white-space:pre">			</span>url = new URL(http);
<span style="white-space:pre">			</span>is = url.openStream();
<span style="white-space:pre">			</span>br = new BufferedReader(new InputStreamReader(is));
<span style="white-space:pre">		</span>} catch (MalformedURLException e) {
<span style="white-space:pre">			</span>// TODO Auto-generated catch block
<span style="white-space:pre">			</span>e.printStackTrace();
<span style="white-space:pre">		</span>} catch (IOException e) {
<span style="white-space:pre">			</span>// TODO Auto-generated catch block
<span style="white-space:pre">			</span>e.printStackTrace();
<span style="white-space:pre">		</span>}
<span style="white-space:pre">		</span>String line = null;
<span style="white-space:pre">		</span>try {
<span style="white-space:pre">			</span>while ((line = br.readLine()) != null) {
<span style="white-space:pre">				</span>sb.append(line);
<span style="white-space:pre">			</span>}
<span style="white-space:pre">		</span>} catch (IOException e) {
<span style="white-space:pre">			</span>// TODO Auto-generated catch block
<span style="white-space:pre">			</span>e.printStackTrace();
<span style="white-space:pre">		</span>}


<span style="white-space:pre">		</span>Gson gson = new Gson();
<span style="white-space:pre">		</span>Log.e("sb.", sb.toString());
<span style="white-space:pre">		</span>Json json = gson.fromJson(sb.toString(), Json.class);
<span style="white-space:pre">		</span>Log.e("json", json.getResultCode());
<span style="white-space:pre">		</span>List<Totel> totel = json.getInfo().getMerchantKey();
<span style="white-space:pre">		</span>for (Totel t : totel) {
<span style="white-space:pre">			</span>UserBean userbean = new UserBean();
<span style="white-space:pre">			</span>userbean.setName(t.getName());
<span style="white-space:pre">			</span>userbean.setCoupon(t.getCoupon());
<span style="white-space:pre">			</span>userbean.setLocation(t.getLocation());
<span style="white-space:pre">			</span>userbean.setDistance(t.getDistance());
<span style="white-space:pre">			</span>userbean.setPicUrl(t.getPicUrl());
<span style="white-space:pre">			</span>userbean.setCardType(t.getCardType());
<span style="white-space:pre">			</span>userbean.setCouponType(t.getCouponType());
<span style="white-space:pre">			</span>userbean.setGroupType(t.getGroupType());
<span style="white-space:pre">			</span>mlist.add(userbean);
<span style="white-space:pre">		</span>}


<span style="white-space:pre">		</span>return mlist;
<span style="white-space:pre">	</span>}
}
-------------------------------------------------------------------------------------------------------------------------------------------------------
这样就把几个类写完了,可以实现以上所写功能
另外这里把Xml补上,这里主要有两个XML,第一个就是界面简单布局和ListView,代码如下:
<pre name="code" class="html"><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="40dp"
        >

        <ImageView
            android:layout_marginTop="5dp"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginLeft="5dp"
            android:src="@drawable/btn_back" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_margin="8dp"
            android:layout_marginLeft="5dp"
            android:text="我的关注"
            android:textColor="@android:color/black"
            android:textSize="18dp" />
    </LinearLayout>

    <ListView
        android:id="@+id/totellistview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp"
        android:layout_marginLeft="10dp" />

</RelativeLayout>

第二XML主要就是是适配器里需要的,用于显示ListView里每一项里面的TextView(显示内容)等
 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >


    <ImageView
        android:id="@+id/imgs"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"/>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >


        <TextView
            android:id="@+id/listtex1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:singleLine="true"
            android:text="fmsdpgfeggf"
            android:textColor="@android:color/black" />


        <TextView
            android:id="@+id/listtex2"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginLeft="10dp"
            android:textColor="@android:color/holo_red_dark" />


        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >


            <TextView
                android:id="@+id/listtex31"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="35dp"
                android:ellipsize="end"
                android:singleLine="true"
                android:textSize="12dp" />


            <TextView
                android:id="@+id/listtex3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="35dp"
                android:layout_toRightOf="@id/listtex31"
                android:textSize="12dp" />
        </RelativeLayout>
    </LinearLayout>


</LinearLayout>