这是MainActivity的代码
package com.example.com.feida.jsontest; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import android.annotation.SuppressLint; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.Menu; import android.view.MenuItem; import android.widget.ListView; import android.widget.SimpleAdapter; @SuppressLint("NewApi") public class MainActivity extends Activity { private List<News>listNews; private ListView list; Handler mHandler=new Handler(){ @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub switch (msg.what) { case GetAndParseJson.PARSESUCCWSS: listNews=(List<News>) msg.obj; initData(); break; } super.handleMessage(msg); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); list=(ListView)findViewById(android.R.id.list); GetAndParseJson getAndParseJson=new GetAndParseJson(mHandler); getAndParseJson.getJsonFromInternet(); } /** * 将解析后的xml填充到ListView */ protected void initData() { // TODO Auto-generated method stub List<Map<String, Object>>items=new ArrayList<Map<String,Object>>(); for (News news:listNews) { Map<String, Object>item=new HashMap<String, Object>(); item.put("id", news.getId()); item.put("title", news.getTitle()); item.put("time", convertDate(news.getPublishDate())); items.add(item); } SimpleAdapter adapter=new SimpleAdapter(this, items, R.layout.line, new String[] {"id","title","time"}, new int[]{R.id.tvId,R.id.tvTitle,R.id.tvTime}); list.setAdapter(adapter); } @SuppressLint("SimpleDateFormat") private String convertDate(Date publishDate) { // TODO Auto-generated method stub SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); return sdf.format(publishDate); } }
这是运行后LogCat显示的内容
已经卡了一天了,求高手指点
解决方案
40
你这网络不同 好像没有网络权限 加上INTERNET权限 再测试吧