如何将解析Webservice的数据绑定到ListView上面去,就是不知道如何绑定到ListView上面去,数据已经能调用
publicclasstestActivity_1extendsActivity{privateTextViewtxt_first;privateEditTextdisp...
public class testActivity_1 extends Activity{
private TextView txt_first;
private EditText displayText;
private EditText edt_first;
private ListView listView;
private List<Map<String,Object>>listData;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.minelistview);
listView =(ListView)findViewById(R.id.lv);
listData = getData();
listView.setAdapter(new MyAdapter(this,listData));
edt_first = (EditText)findViewById(R.id.edt_first);
displayText = (EditText)findViewById(R.id.editText1);
edt_first = (EditText)findViewById(R.id.edt_first);
txt_first = (TextView)findViewById(R.id.txt_first);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
String atest = edt_first.getText().toString();
getPropInfoParam(atest);
}
});
}
private List<Map<String, Object>> getData(){
List<Map<String, Object>> listData = new ArrayList<Map<String, Object>>();
for(int i=0;i<10;i++)
{
Map<String, Object> map = new HashMap<String, Object>();
map.put("title", "第"+i+"行");
map.put("info", "这是第"+i+"行");
listData.add(map);
}
return listData;
}
public void getPropInfoParam(String atest) {
PropInfoParam param = new PropInfoParam();
param.addProp("in1", "contact ='hb' and Pid = '00001'");
new AsyncWebServiceTask(testActivity_1.this, AccessWeiboService.searchSession, param, new AsyncWebServiceTask.OnPostExecuteListener() {
@Override
public void onPostExecute(Object result) {
List<Tasklist> tasklist = (List<Tasklist>)result;
displayText.setText(tasklist.get(0).getSdesp());
}
@Override
public void onNetwrokException(WeiboException e) {
}
}).execute();//调用AsyncWebServiceTask的execute方法开启线程访问服务
}
} 展开
private TextView txt_first;
private EditText displayText;
private EditText edt_first;
private ListView listView;
private List<Map<String,Object>>listData;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.minelistview);
listView =(ListView)findViewById(R.id.lv);
listData = getData();
listView.setAdapter(new MyAdapter(this,listData));
edt_first = (EditText)findViewById(R.id.edt_first);
displayText = (EditText)findViewById(R.id.editText1);
edt_first = (EditText)findViewById(R.id.edt_first);
txt_first = (TextView)findViewById(R.id.txt_first);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
String atest = edt_first.getText().toString();
getPropInfoParam(atest);
}
});
}
private List<Map<String, Object>> getData(){
List<Map<String, Object>> listData = new ArrayList<Map<String, Object>>();
for(int i=0;i<10;i++)
{
Map<String, Object> map = new HashMap<String, Object>();
map.put("title", "第"+i+"行");
map.put("info", "这是第"+i+"行");
listData.add(map);
}
return listData;
}
public void getPropInfoParam(String atest) {
PropInfoParam param = new PropInfoParam();
param.addProp("in1", "contact ='hb' and Pid = '00001'");
new AsyncWebServiceTask(testActivity_1.this, AccessWeiboService.searchSession, param, new AsyncWebServiceTask.OnPostExecuteListener() {
@Override
public void onPostExecute(Object result) {
List<Tasklist> tasklist = (List<Tasklist>)result;
displayText.setText(tasklist.get(0).getSdesp());
}
@Override
public void onNetwrokException(WeiboException e) {
}
}).execute();//调用AsyncWebServiceTask的execute方法开启线程访问服务
}
} 展开
1个回答
展开全部
你这个代码的结果应该就是
第1行,这是第1行
第2行,这是第2行 这样的结果吧
更多追问追答
追问
是的,结果是这样的,我想要的是Webservice调用出来的数据绑定到Listview上,就是显示在Listview上,请问下Adapter用simpleAdapter是不是更好,请解答,请教我如何修改,我卡在
private List> getData()这一段代码上
追答
你这个顺序有点问题,应该是先获取服务器过来的数据,并解析出来,然后赋值给List,最后在设置adapter,你直接getDate()的话,就相当于给List赋值为你自己定义的第几行数据了,并没有使用到Webservice调用出来的数据啊
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询