後,用一個ArrayAdapter ListView控件重置我使用的是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?
}
我可以使結果到適當的結構化數據重置列表中,但不知道如何做到這一點。有人可以幫忙嗎? :)
現在讓我說......我會告訴你如何去:) – GeekedOut 2012-03-10 15:22:18
啊好吧,這是編譯!謝謝! – GeekedOut 2012-03-10 15:27:12
沒問題,祝你好運 – 2012-03-10 15:30:10