Tôi đang sử dụng một ListAdapter để cư một ListView như thế này:Làm thế nào để thiết lập lại các ListView với ArrayAdapter sau khi lấy dữ liệu
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);
và sau đó tôi đang thực hiện cuộc gọi từ xa đến máy chủ của tôi để có thêm dữ liệu cho danh sách đó với cuộc gọi AsyncTask và khi tôi lấy lại dữ liệu từ máy chủ, tôi không biết cách điền và đặt lại ListView. Cho đến nay tôi có một cái gì đó như thế này:
@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?
}
Tôi có thể đưa kết quả vào dữ liệu có cấu trúc thích hợp để đặt lại danh sách nhưng không chắc chắn cách thực hiện. Ai đó có thể giúp đỡ? :)
Hãy để tôi thử ngay bây giờ ... Tôi sẽ cho bạn biết cách thực hiện :) – GeekedOut
ah ok, nó đang được biên soạn! Cảm ơn! – GeekedOut
Không sao, chúc may mắn –