Activity_quiz.xml vs. fragment_quiz.xml


#1

I’ve bought this book and if I’m to get any use from it I’ll need some service. Thank you very much. I’ve deleted the installations of Android I had and reinstalled it for the second or third time. On page 11 is described the activity_quiz.xml file but its contents are different from the contents of my activity_quiz.xml. When I first set up the package, fragment_quiz.xml was open and had the text that should have been listed in activity_quiz.xml. Should this concern me? Should I still put the layout information listed on page 11 into activity_quiz.xml? If you don’t answer my question, I’ll write a review on amazon saying your service is bad.


#2

It sounds like the problem you may be having is to follow the book exactly on the very latest SDK which apparently doesn’t work. It sounds like the wizards have changed and it’s not generating what you are expecting.

I think that you basically have two options. You can stick with the latest SDK and follow the instructions posted elsewhere on this forum about how to change what the wizard generates or you can try to load an older version of the SDK which does produce the exact results the book says it will. For the former, someone else posted step by step instructions and someone else verified that it worked. For the latter, I posted instructions but with the strong caveat that I haven’t actually tried it myself and nobody has verified that it works.


#3

@ embeddedmatt

Can you please post the links to the relevant post that shows how to use fragments instead of activities in the new SDK wizard ?

Thanks


#4

See if this helps: http://forums.bignerdranch.com/viewtopic.php?f=398&t=8303


#5

Hello:
I found a way to reference the fragment_quiz.xml where I had put the two buttons.
Put the code inside PlaceholderFragment instead…using the method onCreateView.
I had to make the rootView final…not sure why…eclipse told me to…
The program seems to work now…
The code is below
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {

	private Button mTrueButton;
	private Button mFalseButton;
	
	public PlaceholderFragment() {
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		final View rootView = inflater.inflate(R.layout.fragment_quiz, container,
				false);
		mFalseButton = (Button) rootView.findViewById(R.id.false_button);
		if(mFalseButton != null)
		{
	    	mFalseButton.setOnClickListener(new View.OnClickListener() {
	            @Override
	            public void onClick(View v) {
	                Toast.makeText(rootView.getContext(),
	                           R.string.correct_toast,
	                           Toast.LENGTH_SHORT).show();
	            }
	       });
		}
		mTrueButton = (Button) rootView.findViewById(R.id.true_button);
		mTrueButton.setOnClickListener(new View.OnClickListener() {
	            @Override
	            public void onClick(View v) {
	                Toast.makeText(rootView.getContext(),
	                           R.string.incorrect_toast,
	                           Toast.LENGTH_SHORT).show();
	            }
	        });	
		return rootView;
	}
}

}


#6

That’s great. For others though, especially beginners, it will probably be less frustrating to eliminate the fragment. The authors’ approach seems to be to get you to understand activities first before they introduce fragments. Unless you know what you’re doing, I think you’re just asking for trouble leaving that fragment around.


#7

I agree with Matt. I am new to Android programming (which is why I bought the book in the first place), so I just removed the fragments altogether. The books mentions they will go over fragments in later chapters, so we should still be able to get experience with fragments later.


#8

I am a middle/high school STEM teacher planning to a teach a class on creating Android apps and just starting through the learning process. I have been stalled in my preparation by the issue of this activity/fragment forum as well as several other ‘it really isn’t like the book’ from other references on app development. While the solution described is fine … it’s a solution to THAT problem which apparently results from changing Android development versions, is there a big picture approach to addressing this issue (and others) that can actually be explained to those trying to learn app development? The alternative is (apparently) and endless list of inconsistencies that must be thrashed through … okay perhaps for software folks who’s head is numbed by years of wall pounding but really poor for trying to get young people interested in programming and the potential for app development.


#9

I haven’t completed the book yet, but this is actually the only issue I have run into where it doesn’t work exactly like the book says it will. Unfortunately it bites you right off the bat. The solution isn’t that hard, but you need to do it each time you create a new project using the wizard.

That being said, I don’t think you are going to be able to teach Android development to high school students. Are they already up to speed on Java because they will need to be. The API is massive and complex. The simplest things like rotating the device can throw quite a curve because of the way Android handles resources. At the very minimum I think you’ll have to make some massive simplifications. I have been a professional developer on various systems for about 20 years and this is a steep learning curve. Most of my career has been embedded systems, but I’ve done some Windows and PalmOS development and found them to be much simpler.


#10

Hi,
I too hit this issue today. I tried the method of removing the 4.4 SDK and emulator, and installing 4.0 versions, using SDK Manager.
Started all over again, however it still created the fragment_quiz.xml file etc.
So I deleted the whole ADT install, windows folders and all, and copied an adt bundle from a previous attempt at learning Android programming from a year ago:
adt-bundle-windows-x86_64-20130219.zip

Start all over again, at last it looks like the book.

I don’t know where old adt bundles can be obtained, but maybe someone else knows?

Regards
John Maltby


#11

[quote=“JohnMaltby”]Hi,
I too hit this issue today. I tried the method of removing the 4.4 SDK and emulator, and installing 4.0 versions, using SDK Manager.
Started all over again, however it still created the fragment_quiz.xml file etc.
So I deleted the whole ADT install, windows folders and all, and copied an adt bundle from a previous attempt at learning Android programming from a year ago:
adt-bundle-windows-x86_64-20130219.zip

Start all over again, at last it looks like the book.

I don’t know where old adt bundles can be obtained, but maybe someone else knows?

Regards
John Maltby[/quote]

I found the mentioned bundle here:
downloads.puresoftware.org/files … dt-bundle/