Personal image-based menu for android - android

I'm quite new to android and have a questen concerning an personal menu.
I want to make several activities use one menu. So i created a header.xml file, which I include in all the activities. There are 4 images in the header, I want to make them clickable (which is no problem with the android:onClick function), and I want to show the user which activity is running.
So i want to replace the "activity 1" image with an "activity 1 active" image and so on. When clicking on "activity 3", the menu should use following images for example:
activity 1, activity 2, activity 3 ACTIVE, activity 4
Furthermore, the active images should not be clickabel, because this would refresh the page.
I would be happy about ideas how to solve it! (project should run with android:minSdkVersion="8")
greets

For showing the user that he is in which activity you can show a Long or short Toast message in OnCreate like
Toast.makeText(getApplicationContext(), "Welcome in activity 3",
Toast.LENGTH_LONG).show();
And for Stop clicking function you can cancel the OnClick() of your button by using:
image3.setClickable(false);

Related

Appropiate intent flags Android for background tasks?

I am working in an Android project. I have 3 Activities (Home, Loading, Menu). The first activty (Home) calls in a background task (when the server answers) to "Menu Activity", but, meanwhile the "Loading" Activity is called for displaying feedback to user. My problem is that when I am in the Menu Activity and I press the back botton, the app shows the Loading activity, and it is wrong. I have been testing different flags, but I have not get the solution.
Can anyone help me, please ?

how to create contents in an activity dynamically

I am developing an android application, in which user can take a test and get his score.
So, I have created a database with 50 questions and I want to choose a question number randomly using Random class and retrieve that question from database and show it in an Activity. And by clicking "Next question" button in the activity, I want the same activity to be loaded with different question. How can I write the code for this?
Why do you want to load the same Activity again?
I'd create an activity (fragment), with the main design, and a function (call it reDisplay()), which displays the question, the answers, etc. In the onCreate(), I'd call this function, and every time, the user clicked on the "Next question" text, I'd save them answers, and call the reDisplay() function, to show an other questin.

Display dialog box when application close from android code

I am getting problem data loss during application close, is there any idea when user close application any action(like click menu or back button) , I want to display message when actually application close in one step, not back button for different activity.
if i have 5 activity , i want to one step know application close , user running any activity among 5.but here i used back button each 5 activity but i want to one step, and if user click menu at that , i also display message you are going to close application.
Create an Activity class as a BaseActivity and extend it in all 5 activities.
Then override onBackPressed method in BaseActivity.
This way you have not to copy your logic in 5 (or more places).

back button return the application to inconsistent state

Today I was testing my app (wich is a very simple note application) but some strange behaviour occur .
The app consists of a big ListView which displays all the notes and a button to make a new note (activity A).
When I press the button to "Add new note",it takes me to the activity B
(with all the fields like title and text).
When I press "Add" ,it take me back to the activity A and displays ok
the new Note .
The thing is that I started pressing BACK and it began to take me "back in time" where some notes were still not created,until it reached the time they were 0 notes .
Since I am new to Android devel ,is this normal or is it something wrong with my app ?
When you go from one activity to another then you should finish your activity and then start new activity.
Try the below code:
finish();
startActivity(new Intent(CurrentActivity.this,NewActivity.class));
You probably need to implement some sort of refresh method to update your ListView. Depending on how you are persisting the data, you could create a method that retrieves the latest data and then updates the adapter for the ListView. Once you have that implemented, you should call the method in onResume().

Android Multi-Screen Application

How do you handle multiple screens in an android application? I have developed with the tab bar at the bottom without problem, however what I am wanting to do is replace all the content on the screen with the content from a new .xml layout file I have created in the project. Additionally, how would I tie the back end code to the new layout file? I'm sure this question probably exists already and is googleable (may have made up a new word). However, I don't know exactly what it is that I am looking for. Thanks in advance for your help.
What you need to do is, create a new Activity and add it to the AndroidManifest.xml:
<activity android:name="ActivityClassName" android:label="Label for the Activity"></activity>
and can be called in a method:
public void startActivity() {
Intent someName = new Intent(CurrentClass.this, ActivityClassName.class);
startActivity(someName);
}
Android applications generally use a separate Activity for each screen, and switch between them using Activity.startActivity and Activity.startActivityForResult. You can pass arbitrary data to an Activity via Intent.putExtra.
Hope this helps,
Phil Lello
It really depends on how you want your application to flow.
Let's consider the scenario where a user does the following:
Starts your first activity
Presses the 2nd tab
Presses the 3rd tab
Presses the back button
If you use a separate activity for each screen, then the following would happen
Activity 1 is started
Activity 2 is started
Activity 3 is started
Activity 3 is closed, user returns to Activity 2
(in this case pressing the back button again would you take you back to Activity 1, and pressing it again would exit your application)
If you used one activity for all the tabs, then the following would occur
Activity 1 is started
Activity 1 sets tab content to tab 2 content
Activity 1 sets tab content to tab 3 content
Activity 1 is closed, user returns to home screen
If you are using a screen with tabs, then the second method (a single Activity with a TabHost or similar) is the preferred method, otherwise the user will end up making a large activity-stack just switching between tabs (meaning if they switch between tabs a lot they'll have to press the back button a lot of times to exit).
If you want to go for the single activity approach, then do some research on TabHost and TabContentFactory. In the createTabContent method of your factory you can inflate a View/layout from XML to set as the tab content using View.inflate. Look those up and come back ask another question if you get stuck ;)
i think you may want to play with more than one activity.... you can have multiple activities and one xml for each of them... in this way you can have different screens... check these links. Multiple Activities, Creating an Activity.... hope this helps...

Categories

Resources