Domanda

How should I write my XML file, where should I put it and how should I reference them in the activity?

This is what I got:

myView = getLayoutInflater().inflate(R.???someplace???.???somename???, null);

What should be set instead of someplace and somename ? And if I have created this XML with 2 elements (a TextView and a LinearLayout, for example) how can I make myView look like the first element and mySecondView look like the other element in that XML?

After solving it, will mainView.addView(myView) make myView appear in the Activity with the pre-defined style?

I've been reading that it is the best solution for defining style in a separate XML file and then applying it to a View created programmatically.

È stato utile?

Soluzione

See this sample code for inflating view..

{
View headerView = inflater.inflate(R.layout.icms_article_detail_header, null, false);
articleDetailDataProvider = new IcmsArticleDetailDataProvider(mContext);
txtPageIndicator=(IjoomerTextView)headerView.findViewById(R.id.icmsTxtIndicator);
imgFavorite = (ImageView) headerView.findViewById(R.id.icmsImageFavorite);
imgShare = (ImageView) headerView.findViewById(R.id.icmsImageShare);
list.addHeaderView(headerView);
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top