I have been working on an application that has a bunch of formulas in it. The user can select which formula they need to use, input the numbers/variables, and the program will return whatever answer they are looking for. Each formula has its own class and since there are so many classes I sorted them into separate packages.
For Example, I might have 3 packages (Volume, Area, and Main).
In the Volume package, I might have 2 classes (Cube_Volume, and Sphere_Volume).
In the Area package, I might have 3 classes (Square_Area, Circle_Area, and Triangle_Area).
In the Main package, I might have 1 class (Main_Activity).
I am currently trying to allow the user to bookmark their favorite formulas. If a user is in the Sphere_Volume class, they can bookmark that class. How I am currently attempting to do this is when the user chooses to bookmark the class, the application saves the string returned by this code.
this.getLocalClassName()
The string that is saved (I am using an SQL database to store the string) will look something like this:
com.example.area.Triangle_Area
The bookmarks that the user saves (like the one shown above) are displayed in a Listview in the Main_Activity class. Obviously, when the user clicks on a bookmark in the Listview, I would like the program to start the corresponding activity.
So finally, the question is: How can I use an Intent to start any activity in any other package when the string provided is something like com.example.area.Triangle_Area?
Thanks for any and all answers! Please comment if I need to elaborate more on my issue.
Since Intent constuctor accepts the component class as its parameter, it's as simple as this:
context.startActivity(new Intent(context, Class.forName("com.example.area.Triangle_Area"));
Related
So I am making a simple wine list app. There are three main activities.
MainActivity - this is where the list of wines is, along with a FAB that takes you to the AddWineActivity. Each list item on this page only shows a thumbnail, the wine name, price, and rating.
AddWineActivity - has a couple of EditTexts (to get the wine's name, price, and description), a ratingbar (to get the wine rating), and a button that converts the details into strings and puts them into into intent extras.
WineDetailsActivity - This will have a nice page that has all of the details for the wine in the list you clicked on.
I have the app pretty much working how I want it to currently. The only thing is that I need to actually save the list of wines so it wont reset after you go back in to add another wine, or if you leave the app and come back.
Here is the tricky part (which doesn't help since I don't know too much about saving to device anyway yet). I am adding to the arraylist using a Class.
I have a Wine class that has a constructor that looks like this:
public Wine(String mWineName, String mWinePrice, String mWineRating, String mWineDescription, int mWineImageResourceID) {}
So then on the MainActivity, to add to the list it looks like this
wines.add(new Wine(getIntent().getStringExtra("WINENAME"), getIntent().getStringExtra("WINEPRICE"), getIntent().getStringExtra("WINERATING"), getIntent().getStringExtra("WINEDESCRIPTION"), R.drawable.mywinelogo));
What would be the recommended way to add a list that looks like that to the device? Would it still be shared preferences or am I not on the right track?
If more details about the app are wanted, just ask for them and I'll provide them.
Thanks!
What would be the recommended way to add a list that looks like that to the device? Would it still be shared preferences or am I not on the right track?
In the end, you have a tabular data structure: rows (wines) and columns (name, rating, etc.).
When you have a tabular data structure, save it to something that is table-friendly. That could be a SQLite database or some form of file (e.g., JSON, XML).
SharedPreferences is not well-suited for this. You could convert the table to JSON and store it as a string preference, but that's relatively uncommon. IMHO, that would only make sense if most of the rest of your data were more natural for SharedPreferences (e.g., you were using PreferenceScreen to collect them) and wanted to keep everything together.
I'm trying to create a my own way of selecting because I want to select across multiple edittexts. And selection might include other Views also (not just text).
I have so far found that the android.text.Selection class handles text selecting. As this class is a static (constructor private) class it ensures that in the application there is no way to create 2 or more selections simultaneously (because when you add a new selection,it has to be done through this class and this class removes the previous selection when adding a new one). Therefore there is no way to select text in multiple edittexts at the same time.
So I'm trying to create my own way of selecting (yes, manually add a backgroundColorSpan when user does what is done when selecting).
But how do I deal with the anchors? As android is open source I'd like it if I can find the class that handles selection anchors (in other words the class which determines when to call Selection class to extend selections to the next line based on how user drags the anchor.) So in which class does this happen exactly?
For anyone interested it's the,
android.widget.Editor class
I am creating a service application where in the person who uses the service fills his data and signs it
Now I want to create a blank page where I can take the signature of the client on the TAB itself. So please help to do this.How can I implement it.
I have refereed to this http://tavmjong.free.fr/INKSCAPE/MANUAL/html/Paths-Creating.html link but some how I am not able to work with it.
Please help.Thanks
You can do it using GestureOverlayView. Example in the links: http://www.intertech.com/Blog/android-gestureoverlayview-to-capture-a-quick-signature-or-drawing/
Specifically, create a GestureOverlayView in your layout xml file, then in your Activity class capture the gesture and save it as bitmap image.
Go through the developer API if you want to have specific function for your page, especially for events like Gesturing or Gesture Finish : http://developer.android.com/reference/android/gesture/GestureOverlayView.html
Hope that helps
I've one seen on an application for iPhone an interesting idea which consists of showing a list of options when we click on an area for text edition. For example, imagine I have a field called "City" (EditText) which I am suposed to enter the name of the city. When clicking on the EditText, a list automatically shows up with a few city suggestions (e.g. defined by the programmer) which can be selected. If the user doesn't like the suggestions, he writes the city himself and this city can be saved for this list for future.
I want to programme this on my App for android. I need that, when clicking on the EditText for introducing the data, a list automatically shows up with some suggestions defined by me (Programmer). However, I don't know how this can be done. I've googled but maybe it's hard to find the correct keywords to find a similar topic.
The idea is that the user should use the names already written in the list in 90% of the time and just write himself the new ones when it's necessary. Something like a dropdown list but with possibility of writing new stuff instantly without specific option.
How can this be achieved?
You Need Something Like View in android Named as
AutoTextComplete
Examples How to use this :
help
Best of luck
You can consider focus changed listener for Edittext,
when focus is gained you can show a context menu to choose data from.
In my app, i have you put in some information through some edit text. Then you hit this button and it starts another activity that does some calculations and then displays results through text views. Well i want to be able to save all of those text views, and then open them up later. On the home screen i have a load button. When you click it, I want to be able to see the stuff I've saved and be able to open it by clicking on it. I'm new to android, so I'm having a hard time figuring this out. How should I go about doing this?
Use SharedPreferences...Check out..
http://www.vogella.com/articles/AndroidFileBasedPersistence/article.html
http://androiddeveloperspot.blogspot.in/2013/01/sharedpreference-in-android.html
this will help.
I see two questions in your question. The first is how to pass data from one Android activity to another.
The best way to do that is by using the putExtra method of the Intent class and then the getExtras method to extract the data in the receiving activity. Please see this SO quest and answers for more details.
For your second question, how to save data that can be recalled at a later by the main activity, you can use the SharedPreferences APIs. See this web page for more information on that. Basically the shared preferences APIs allow you to save key-value pairs of information which in your case can be field names (keys) and their associated values. For this you would want private preferences and pick a unique name for this preference file.