Android and XML Usage - android

Hai,
I am developing a Puzzle in Android.
The puzzle is something like finding a number.
It contains 7 steps.
Here I use 7 xml files
Each file is meant for some operations
The 7th file displays the output.
There is a Try again button in the 7th file and when the user clicks on that button, it should call the 1st xml file and repeat the same process again.
The code for that navigation is something like:
setcontentView(R.layout.main1); where main1 is the 1st xml file.
The problem is that, the control goes to the 1st file but the processes can't be repeated.ie. the controls inside that page will be in inactive state.
Can any one give some suggestions here?

Another option would be to raise the initial Intent on the Try Again button press. This should reinitialise the application, and should have the added benefit of allowing the user to go Back to their previous result.
These are only ideas though, I'm a noob at Android development....

Related

What is good way to backtrack a function in your Android app (like a button) to the code that implements it?

I have a project that I did not develop but am trying to fix bugs in. There's a button that I press and then a bug occurs. I want to find out where in the code this button is implemented but its hard to trace it since there are so many classes and layout files. Usually, if there's text associated with the button, then I find the string in my strings.xml file and work my way back. Unfortunately, this button doesn't have any text associated with it.
Hey just connect your actual android phone and run the app on it and also open logcat, when you will click that button logcat should hopefully display all the errors and you can go to the function.
Try this and comment me back if it works
This is a unconvential method, but I used it in the beginning aswell. In Android Studio press CTRL + H to open the Find in Path dialog. This will search the whole project.
For a Button you might want to search e.g. setOnClickListener, Button etc. and navigate it down by this approach. This method will also find dynamically created Views in case it's not in the layout.xml

File browser with a ListView and back button

I am working on a simple file explorer using android os.
I get the whole directory structure like filesize, filenames, directory name via a json object and put them in a list view. On 1) you can see, what I finally want to do.
The problem is, that the items have a complete other style like the back botton, so I may have to deal with two list views (one for the back button in every sub directory and one for the items like the 2nd variant in my picture). But having two listviews, the first one should resize in the root directory, so that it fits in the height like the version with a back button.
Do you have any ideas? I hope you unterstand, want I want.
1]: http://www.basepic.com/2014/Mar/13/97965279.png
WOuldn't it be better if you just add a button with the visibility GONE. And only make it visible on the top if you want to show the back button else just leave it hidden? Why a seperate listview for just one button?

Changing the clickable state of a button in a layout from another activty

I am new to android app development. I am developing a puzzle game with some levels.
I am having a levelmenu.xml, Levelmenu.java, and xml and java files of the levels. if the user finishes a level next level should unlock for them.
I am using buttons in levelmenu.xml and on clicking a button respective intent will be activated which will open the respective level. each level is a separate activity.
So i want to change the icon and clickable state of the button in levelmenu activity from another activity(the respective level activity).How to do it. please help me.
Since it is a game , I believe that you need to save the user progress somewhere (may be preference).Once you complete a level you can set the progress in a file(preference).
In onResume() method of your Levelmenu activity look the progress in that file and display the menu buttons accordingly.
By doing so you can also handle the use case of allowing the user to continue from his last progress(level) even after stopping and restarting the app.
NB- this answer is written specific for this question, may not be useful in other scenarios.

Are Activities in Android development akin to Forms in C#, Panels in Java, etc.?

I'm just getting started with Android development after having extensive experience with C#, VB, Java, etc. I'm trying to wrap my mind around the workings of it before moving forward to make sure I'm approaching things correctly.
Right now, I conceptualize of an Activity in Android as similar to a Panel in Java, a Form in C#: a layout/UI with interactive elements and code that responds to those elements.
Is that the right way to think about it?
The app I'm developing to learn the system is a basic flashcard app. After opening the app, you'll be able to choose to Load some flashcards, Create new cards, or Copy other cards. I'm thinking that my home Activity would be three buttons, one for each task, and each button would launch an Activity for each of those tasks - Loading, Creating, or Copying. Would that be the right way to think about this?
You are correct, an activity is a screen that the user will be presented which will consist of user interface elements such as edit texts, text views button etc that the user can interact with.
The activity will load up an XML file which will contain the user interface elements and the layout of how the contents of the activity should be displayed. This XML file is found in res > layout.
Its quite common for your layouts xml file to be the same as the activity name, i.e if you have an activity called MainActivity then you would have a layout file called main_activity.xml.
Then in the activities onCreate method you would use setContentView(R.layout.main_activity);
Hope this helps

Spinner inside custom ListView freezes on returning from another activity

Hello all here is my problem.
My app's listview (which is inside a tab widget) contains various types of rows. I have had many problems setting this up and here is another 1. Please see here for the code, which basically remains the same.
I use another activity (a custom implemented ES file explorer) which is a filebrowser dialog to open a file. The data from the file is sent to the listview.
When it shows the list and I click on the spinner the screen darkens and freezes. If I press the back button the darkening disappears, the listview becomes clickable but the spinner still is not. The only way out is if I flip to another tab widget and back again (there are 2 separate ones) the spinner will work again.
I should say that the spinner works just fine if I do not load files from the other activity.
So I guess in other words there is a problem of focus or something when switching and killing activities.
I hope you can help.
EDIT
after some more trying, sometimes after loading the file from the browser it will return to a black screen where the listview is there but not visible.
eg you can click on it and the editor opens.
Hi well again it took ages but here was the problem.
the custom listview had
this.setDescendantFocusability(FOCUS_BEFORE_DESCENDANTS);
set
so all I had to do was set
holder.techniquespinner.setDescendantFocusability(parent.FOCUS_BEFORE_DESCENDANTS);
for the spinner and voila; I haven't tried but it should probably go in the xml file.
Thanks to anybody who looked.
EDIT
Crap I spoke to soon. It still doesn't work.
There is 2 tabwidgets inside a flipper.
If returning from the browser to the tab where it left WITHOUT flipping the flipper it works.
Flip once, back again and then to the browser does not work.
I'm not even sure what code to post. It is quite complex.
FINAL EDIT
This is how I fixed it.
flipper.showNext();
and then back again.
It somehow refreshes the view brings it back to focus and useable again.
It isn't pretty but it works.

Categories

Resources