【发布时间】:2014-02-11 07:38:21
【问题描述】:
ProgressTask.java
public class ProgressTask extends AsyncTask<String, Void, Boolean>{
private ProgressDialog dialog;
private ListActivity activity;
private Context context;
ArrayList<HashMap<String, String>> jsonlist = new ArrayList<HashMap<String, String>>();
ListView lv ;
private static String url = "http://api.cartperk.com/v1/supportedoperator";
private static final String OPCODE="code";
private static final String OPNAME="name";
public ProgressTask(ListActivity activity) {
this.activity = activity;
context = activity;
dialog = new ProgressDialog(context);
}
protected void onPreExecute() {
this.dialog.setMessage("Progress start");
this.dialog.show();
}
@Override
protected void onPostExecute(final Boolean success) {
if (dialog.isShowing()) {
dialog.dismiss();
}
ListAdapter adapter = new SimpleAdapter(context, jsonlist,
R.layout.list_item, new String[] { OPCODE, OPNAME}, new int[] {
R.id.opcode, R.id.opname});
activity.setListAdapter(adapter);
lv = activity.getListView();
}
protected Boolean doInBackground(final String... args) {
JSONParser jParser = new JSONParser();
JSONArray json = jParser.getJSONFromUrl(url);
for (int i = 0; i < json.length(); i++)
{
try {
JSONObject c = json.getJSONObject(i);
String opcode = c.getString(OPCODE);
String opname = c.getString(OPNAME);
HashMap<String, String> map = new HashMap<String, String>();
map.put(OPCODE,opcode);
map.put(OPNAME,opname);
jsonlist.add(map);
}
catch(JSONException e)
{
e.printStackTrace();
}
}
return null;
}
它在list_item、R.id.opcode、R.id.opname 中显示错误我应该创建一个新的 XML 文件并在那里编写代码,否则会动态生成我目前的布局文件如下所示,你们能帮我吗
<RelativeLayout>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<RealativeLayout>
无法理解。
【问题讨论】:
-
如果我想创建一个 XML 文件,你能给我一个想法
-
如果可能,请发布您的
list_itemxml 和 logcat。 -
@user3263528 你在 re/layout 文件夹中有一个名为
list_item.xml的 xml 吗?? -
不,我没有 list_item.xml
-
我问如何在上面显示的java的基础上创建一个XML
标签: android xml android-layout listactivity listadapter