//主界面
package com.bwie.test;
import java.util.ArrayList;//adapter 界面
package com.bwie.test.adapter;
import java.util.HashMap;
import java.util.List;
import com.bwie.test.R;
import com.bwie.test.bean.Person;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
public class MyAdapter extends BaseAdapter {
private Context context;
private List
private static HashMap
public MyAdapter(Context context, List
// TODO Auto-generated constructor stub
this.context = context;
this.mlist = mlist;
isSelected=new HashMap
initData();
}
private void initData() {
// TODO Auto-generated method stub
for (int i = 0; i < mlist.size(); i++) {
getIsSelected().put(i,false);
}
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return mlist.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return mlist.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
//viewHolder的优化
ViewHolder viewHolder;
if (convertView==null) {
viewHolder=new ViewHolder();
convertView=View.inflate(context,R.layout.list_item,null);
viewHolder.tvname=(TextView) convertView
.findViewById(R.id.text_name);
viewHolder.ck=(CheckBox) convertView.findViewById(R.id.checkBox1);
convertView.setTag(viewHolder);
} else {
viewHolder=(ViewHolder)convertView.getTag();
}
viewHolder.tvname.setText(mlist.get(position).getChannelName());
viewHolder.ck.setChecked(getIsSelected().get(position));
viewHolder.ck.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked){
mlist.get(position).setCheck(true);
}else{
mlist.get(position).setCheck(false);
}
}
});
return convertView;
}
public static HashMap
return isSelected;
}
public static void setIsSelected(HashMap
MyAdapter.isSelected = isSelected;
}
public static class ViewHolder {
TextView tvname;
public CheckBox ck;
}
}
//person界面
package com.bwie.test.bean;
public class Person {
private String uid;
private String channelName;
private String channelKey;
private String descr;
private String createDate;
private String channelLogo;
private String channelVersion;
private boolean isCheck;
public Person(String uid, String channelName, String channelKey,
String descr, String createDate, String channelLogo,
String channelVersion, boolean isCheck) {
super();
this.uid = uid;
this.channelName = channelName;
this.channelKey = channelKey;
this.descr = descr;
this.createDate = createDate;
this.channelLogo = channelLogo;
this.channelVersion = channelVersion;
this.isCheck = isCheck;
}
/**
* @return the uid
*/
public String getUid() {
return uid;
}
/**
* @param uid the uid to set
*/
public void setUid(String uid) {
this.uid = uid;
}
/**
* @return the channelName
*/
public String getChannelName() {
return channelName;
}
/**
* @param channelName the channelName to set
*/
public void setChannelName(String channelName) {
this.channelName = channelName;
}
/**
* @return the channelKey
*/
public String getChannelKey() {
return channelKey;
}
/**
* @param channelKey the channelKey to set
*/
public void setChannelKey(String channelKey) {
this.channelKey = channelKey;
}
/**
* @return the descr
*/
public String getDescr() {
return descr;
}
/**
* @param descr the descr to set
*/
public void setDescr(String descr) {
this.descr = descr;
}
/**
* @return the createDate
*/
public String getCreateDate() {
return createDate;
}
/**
* @param createDate the createDate to set
*/
public void setCreateDate(String createDate) {
this.createDate = createDate;
}
/**
* @return the channelLogo
*/
public String getChannelLogo() {
return channelLogo;
}
/**
* @param channelLogo the channelLogo to set
*/
public void setChannelLogo(String channelLogo) {
this.channelLogo = channelLogo;
}
/**
* @return the channelVersion
*/
public String getChannelVersion() {
return channelVersion;
}
/**
* @param channelVersion the channelVersion to set
*/
public void setChannelVersion(String channelVersion) {
this.channelVersion = channelVersion;
}
/**
* @return the isCheck
*/
public boolean isCheck() {
return isCheck;
}
/**
* @param isCheck the isCheck to set
*/
public void setCheck(boolean isCheck) {
this.isCheck = isCheck;
}
public Person(){}
}
//数据请求界面
package com.bwie.test.httpUrlConnection;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
public class HttpUrlGetConnectinGet {
public static String HGet(){
String result="";
String path="http://121.42.8.95:8090/AndroidServer/yk.json";
try {
HttpGet h=new HttpGet(path);
HttpClient httpclient=new DefaultHttpClient();
HttpResponse httpResponse = httpclient.execute(h);
if(httpResponse.getStatusLine().getStatusCode()==200){
HttpEntity httpEntity = httpResponse.getEntity();
result=EntityUtils.toString(httpEntity,"utf-8");
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return result;
}
}