I have an application for a working tablet, which I am now trying to make on phones as well. There are two fragments on the table on the screen of the list fragment and the fragment of the part. When a fragment of the list appears on the phone and a new action is created when you click on a list item. This operation simply creates a fragment in the onCreate() method and writes it to the screen as follows.
// Place an DeallDetailsFragment as our content pane DealDetailsFragment f = new DealDetailsFragment(); getFragmentManager().beginTransaction().add(android.R.id.content, f).commit(); getFragmentManager().executePendingTransactions();
This works as expected, however, from within this activity I need to tell the fragment which details to load and display. In my DealDetailsFragment class, I have an updateDeal() method that updates the contents as follows.
if (deal==null) { // could be null if user presses the loading deals list item before it loads return; } this.deal=deal; if (dealTitle==null) { // get the view objects only once holder = new ViewHolder(); holder.dealHeat=(TextView) getView().findViewById(R.id.dealDetails_heat_textView); holder.dealPrice=(TextView) getView().findViewById(R.id.dealDetails_price_textView); holder.dealRetailer=(TextView) getView().findViewById(R.id.dealDetails_retailer_textView); holder.dealTitle=(TextView) getView().findViewById(R.id.dealDetails_title_textView); holder.dealDesc=(TextView) getView().findViewById(R.id.dealDetails_desc_textView); holder.goToButton= (LinearLayout) getView().findViewById(R.id.dealDetails_goToDeal); holder.dealImage=(ImageView) getView().findViewById(R.id.dealDetails_imageView); holder.postedBy=(TextView) getView().findViewById(R.id.dealDetails_poster_textView); holder.datePosted=(TextView) getView().findViewById(R.id.dealDetails_date_textView);
getView() returns null when the application is launched on the phone, where only one fragment is shown.
Any ideas? Unfortunately, there are not many examples of fragments on the Internet.
bencallis Feb 28 '12 at 19:44 2012-02-28 19:44
source share