【发布时间】:2012-03-10 15:14:46
【问题描述】:
我正在使用 ListAdapter 来填充 ListView,如下所示:
static final String[] PROBLEMS = new String[] {"one", "two", "three" };
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this, R.layout.my_problems, PROBLEMS));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
之后,我通过 AsyncTask 调用远程调用我的服务器以获取该列表的更多数据,当我从服务器取回数据时,我不知道如何填充和重置 ListView。到目前为止,我有这样的事情:
@Override
protected void onPostExecute(String result)
{
// Unwrap the stuff from the JSON string
String problem_title = null;
String problem_id = null;
try
{
JSONArray obj = new JSONArray(result);
JSONObject o = obj.getJSONObject(0);
Log.d( "Title: " , "" + o.getString("problem_title") );
Log.d( "id: " , "" + o.getString("problem_id") );
problem_title = o.getString("problem_title");
problem_id = o.getString("problem_id");
}
catch ( Exception e )
{
}
// Now not sure what to do :)
// How do I reset the list that I had set up above?
}
我可以将结果转换为适当结构化的数据以重置列表,但不确定如何完成。有人可以帮忙吗? :)
【问题讨论】:
标签: android android-listview android-asynctask android-adapter