也许我不知道关于Android应用开发和xml
的第一件事(但我在Google Play商店有3个应用),但究竟是什么决定了什么时候执行?
为了尝试回答这个问题,我在Log
中的每个类文件的每个方法中插入了FragmentBasics
个语句,这是从标题中的URL下载的文件。
项目结构:
我很惊讶地看到执行顺序是什么。
MainActivity: `````onCreate
HeadlinesFragment: `````onAttach
HeadlinesFragment: `````onCreate
AbsListView: checkAbsListViewlLogProperty get invalid command
ArticleFragment: `````onCreateView
MainActivity: `````fragment_container IS null--two-pane mode
HeadlinesFragment: `````onStart
ArticleFragment: `````onStart
为onAttach
和onCreate
中的HeadlinesFragment
和onCreateView
以及ArticleFragment
中MainActivty
执行HeadlinesFragment
"片段容器之前的原因/方式是空的......"?
为什么onCreateView
没有像ArticleFragment
这样的onCreate
,而只是setContentView
?
我读到HeadlinesFragment
执行此操作:"从布局资源设置活动内容。资源将被夸大,将所有顶级视图添加到活动中。"因为我正在使用"大"设备(平板电脑)和ArticleFragment
以及large\news_articles.xml
是xml
的一部分,是否public class MainActivity extends FragmentActivity
implements HeadlinesFragment.OnHeadlineSelectedListener
{
public void onCreate(Bundle savedInstanceState)
{
Log.w("MainActivity","`````onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.news_articles); // either normal or large
if (findViewById(R.id.fragment_container) == null)
Log.w("MainActivity","`````fragment_container IS null--two-pane mode");
else
{
Log.w("MainActivity","`````fragment_container not null--one-pane mode");
if (savedInstanceState != null)
return;
HeadlinesFragment firstFragment = new HeadlinesFragment();
firstFragment.setArguments(getIntent().getExtras());
getSupportFragmentManager() .beginTransaction()
.add(R.id.fragment_container, firstFragment)
.commit();
}
}
}
导致类被实例化?
我真的觉得我对Android开发几乎一无所知。但我有这三个应用程序......
这里提到的3个类的本质是:
public class HeadlinesFragment extends ListFragment
{
public void onCreate(Bundle _savedInstanceState)
{
Log.w("HeadlinesFragment","`````onCreate");
super.onCreate(_savedInstanceState);
setListAdapter(new ArrayAdapter<String>(getActivity(), layout, Ipsum.Headlines));
}
public void onStart()
{
Log.w("HeadlinesFragment","`````onStart");
super.onStart();
if (getFragmentManager().findFragmentById(R.id.article_fragment) != null)
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
public void onAttach(Activity _activity)
{
Log.w("HeadlinesFragment", "`````onAttach");
super.onAttach(_activity);
}
}
public class ArticleFragment extends Fragment
{
public View onCreateView(LayoutInflater _inflater, ViewGroup _container, Bundle _savedInstanceState)
{
Log.w("ArticleFragment", "`````onCreateView ");
View v = _inflater.inflate(R.layout.article_view, _container, false);
return v;
}
public void onStart()
{
Log.w("ArticleFragment","`````onStart");
super.onStart();
}
}
。
.xml
article_view.xml
的本质:
<TextView android:id="@+id/article" />
news_articles.xml
<FrameLayout android:id="@+id/fragment_container" />
news_articles(large).xml
<LinearLayout>
<fragment
android:name="com.example.android.fragments.HeadlinesFragment"
android:id="@+id/headlines_fragment">
<fragment
android:name="com.example.android.fragments.ArticleFragment"
android:id="@+id/article_fragment"/>
</LinearLayout> [1]: http://i.stack.imgur.com/JPCZu.png
do_install_append() {
# Remove .la files for loadable modules
rm -f ${D}/${libdir}/rygel-${LIBV}/engines/*.la
rm -f ${D}/${libdir}/rygel-${LIBV}/plugins/*.la
}