【发布时间】:2015-07-29 23:34:24
【问题描述】:
通过设备管理器观看我的应用时,我发现了充气器的行为,我希望堆栈溢出社区中的某个人可以帮助我理解。我有一个片段,当它使用布局充气器充气 EditText 时,它会产生两个异步任务。为什么会产生这些,我能做些什么来防止这种情况发生或事后关闭它们?
当我注释掉 EditText 时,在片段加载后我看到了这个:
我的片段看起来像:
public class SearchFragment implements View.OnClickListener{
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String TAG = "HistorySearchFragment";
private static final String ARG_SECTION_NUMBER = "sectionNumber";
public static SearchFragment newInstance(int sectionNumber) {
SearchFragment fragment = new SearchFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.fragment_search, container, false)
return view;
}
}
fragment_search.xml 看起来像
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
tools:context="com.main.SearchFragment"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/search_button_bw"
android:layout_below="@+id/space"
android:isScrollContainer="false">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
/*************************************************
THIS TEXT BOX HERE
/************************************************/
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
/*************************************************
To here
/************************************************/
</RelativeLayout>
</ScrollView >
<Button
android:id="@+id/search_button_bw"
android:layout_width="match_parent"
android:layout_height="70dp"
android:text="Search"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
我已经证实,这只发生在这个片段加载并且任务每次都没有失败时产生。有谁知道为什么会发生这种情况以及如何预防?
【问题讨论】:
标签: android android-layout android-fragments android-edittext android-inflate