3
我想在我的活动中AsyncTask
完成时更新列表片段,但我不确定是否做错了什么。目前,我有一个按钮,启动AsyncTask
:Android刷新AsyncTask后的片段查看
search = (Button)findViewById(R.id.search);
search.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
String productname = prodname.getText().toString().trim();
if (NetworkManager.isOnline(getApplicationContext())){
// Go to Other screen
AsyncFetcher results = new AsyncFetcher(currActivity);
String _url = "http://192.168.1.3:3000/search.json?
utf8=%E2%9C%93&q="+productname;
// progressDialog = ProgressDialog.show(
// ClassifiedsActivity.this, "", "Loading...");
results.execute(_url);
} else {
// Throw some warning saying no internet
// connection was found
}
}
});
一旦我的执行完成后我有以下我的活动范围内的实例片段:
ResultFragment resultfrag = new ResultFragment();
getSupportFragmentManager().beginTransaction()
.replace(R.id.content_frame, resultfrag).commit();
但是它似乎与替换我的内容列表片段。 这是我的布局文件:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
嗨yahya,谢谢你的回应。我加你在这里所描述的方法,也不得不加上 “m_adapter.clear(); \t \t m_adapter.notifyDataSetChanged(); \t \t m_adapter.addAll(this.search_results);”由于适配器仍旧保持对旧的“ArrayList”的引用,因此刷新数据可以工作。 – user2352691 2013-05-06 22:25:36
啊,是的,它当然取决于你如何处理listView及其适配器。我很高兴你做到了:) – yahya 2013-05-07 05:53:58