我正在尝试AsyncTask在我的活动完成时更新列表片段,但我不确定我是否做错了什么.目前,我有一个按钮启动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
}
}
});
Run Code Online (Sandbox Code Playgroud)
一旦我的执行完成,我就会在我的活动中实例化片段:
ResultFragment resultfrag = new ResultFragment();
getSupportFragmentManager().beginTransaction()
.replace(R.id.content_frame, resultfrag).commit();
Run Code Online (Sandbox Code Playgroud)
但是它似乎没有用列表片段替换我的内容.这是我的布局文件:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" …Run Code Online (Sandbox Code Playgroud)