我正在尝试从 asynctask 类中替换一个片段 onPostExecute 方法,但它不会替换任何东西。这是我的标签监听器类:
public class TabListener implements ActionBar.TabListener
{
protected ParentActivity parent;
public FragmentTransaction fragmentTransaction;
public ItemData item = new ItemData();
public TabListener(ParentActivity parent)
{
this.parent = parent;
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
this.fragmentTransaction = ft;
if(this.parent.isNetworkAvailable())
{
//ft.replace(android.R.id.content, new LoadingFragment());
if(tab.getPosition() == 0)
{
new HttpData().execute(ParentActivity.centroUri);
}
else
{
new HttpData().execute(ParentActivity.nvomxliUri);
}
}
else
{
ft.replace(android.R.id.content, new NetworkFragment());
}
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
private class HttpData extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
Parser p = new Parser();
p.run(urls[0], item);
return "";
}
@Override
protected void onPostExecute(String result) {
fragmentTransaction.replace(android.R.id.content, new LaneFragment(item));
}
}
}
我确认执行了 onPostExecute 方法并按预期检索了所需的数据。
谢谢你的帮助。