android ListView以及自定义adapter测试

public class listview extends Activity{
	private LinkedHashMap<String ,String> params;
	private List<LinkedHashMap> data_set;
	private ListView listview;
	private myadapter2 myadapter;
  public void onCreate(Bundle save){
	  super.onCreate(save);
	  setContentView(R.layout.list);
    listview=(ListView)findViewById(R.id.listView1);
Bundle bundle=listview.this.getIntent().getExtras();
	  String date=null;
	  String from_station=null;
	  String to_station=null;
	 date= bundle.getString("date");
	 from_station=bundle.getString("from_station");
	  to_station=bundle.getString("to_station");
	  date="2014-04-20";
	  //怎么会有一个空格多出来的不知道
	  from_station="HZH";
	  to_station="CSQ";
		params=new LinkedHashMap<String, String>();
		params.put(bookInfo.train_date,date);
		params.put(bookInfo.from_station,from_station);
		params.put(bookInfo.to_station, to_station);
		params.put("purpose_codes", "ADULT");
		data_set=new ArrayList<LinkedHashMap>();
		//新开一个线程去读取信息还是?
		/*
		 * 第一步得到response对象
		 * 第二步从response中解析出数据出来
		 */
		/*getbook get=new getbook(bookInfo.get_book,params);
		 * get.init();
		String response=get.getreponse(); 
		jsontest json=new jsontest(response);
	     json.init();
	     data_set=json.get_data();
		 */
		String[] value={"D105","18:25","长沙","杭州东","08:15","10:10","无","有","125"};
		LinkedHashMap<String,String> map;
		  for(int j=0;j<3;j++){
			  map=new LinkedHashMap();
				for(int i=0;i<9;i++){
					map.put(trainInfo.t_query[i], value[i]);
				}
			  data_set.add(map);
		  }
	     myadapter=new myadapter2(this, data_set);
	     int size=data_set.size();
	     if(myadapter==null)
	    	 Log.e("adapter", "null");
	     Log.i("size",""+size);
	     if(listview==null)
	    	 Log.e("listview","null");
	     //if(size>0)
	     listview.setAdapter(myadapter);
	  //data_set=main.
  }

  private class myadapter2 extends BaseAdapter{
    private Context context;
    private List<LinkedHashMap> data_set;
    private String []id;
	public myadapter2(Context context,List<LinkedHashMap> data){
		this.context=context;
		this.data_set=data;
		id=new String[7];
		for(int i=0;i<=5;i++)
			id[i]=trainInfo.t_query[i];
		id[6]="seat";
	}
	public int getCount() {
		// TODO Auto-generated method stub
		return data_set.size();
	}

	@Override
	public Object getItem(int i) {
		// TODO Auto-generated method stub
		return data_set.get(i);
	}

	@Override
	public long getItemId(int i) {
		// TODO Auto-generated method stub
		return i;
	}

	@Override
	public View getView(int i, View arg1, ViewGroup parant) {
		// TODO Auto-generated method stub
		/*
		 * "station_train_code","arrive_time","to_station_name","from_station_name","lishi","start_time",
		"yw_num","yz_num","wz_num"	
		7num
		 */
		View v=arg1;
		if(v==null){
			LayoutInflater m_layout=LayoutInflater.from(context);
			v=m_layout.inflate(R.layout.item, null);
		}
		LinkedHashMap<String,String>  map=data_set.get(i);
		TextView textview=null;
		String str=null;
		String seat="seat";
		textview=(TextView) v.findViewById(R.id.arrive_time);
		str=map.get("arrive_time");
		textview.setText(str);
		textview=(TextView) v.findViewById(R.id.lishi);
		textview.setText(map.get("lishi"));
		textview=(TextView)v.findViewById(R.id.from_station_name);
		textview.setText(map.get("from_station_name"));
		textview=(TextView) v.findViewById(R.id.start_time);
		textview.setText(map.get("start_time"));
		textview=(TextView)v.findViewById(R.id.station_train_code);
		textview.setText(map.get("station_train_code"));
		textview=(TextView)v.findViewById(R.id.to_station_name);
		textview.setText(map.get("to_station_name"));
		str+="硬座:"+map.get("yz_num")+"硬卧:"+map.get("yw_num")+"无座:"+map.get("wz_num");
		textview=(TextView) v.findViewById(R.id.seat);
		textview.setText(str);
		return v;
	}
	  
  }
  
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值