ID resource in Android XML - Java for Android App Development

Hi
In the tutorial that i am reading says :
Any View object may have an integer ID associated with it, to uniquely identify the View within
the tree. When the application is compiled, this ID is referenced as an integer, but the ID is
typically assigned in the layout XML file as a string, in the id attribute. This is an XML attribute
common to all View objects (defined by the View class) and you will use it very often. The
syntax for an ID, inside an XML tag is:
android:id="@+id/my_button"
The at-symbol (@) at the beginning of the string indicates that the XML parser should parse and
expand the rest of the ID string and identify it as an ID resource . The plus-symbol (+) means that
this is a new resource name that must be created and added to our resources (in the R.java file).
My question is this : In phrase ID resource , the resource word what does mean ???
I know about resources in Android a little but i guess that the ID resource is different from that . Please give me help
Thanks for your helps

All data from xml files (like layouts, menus, etc.) is called resource because it's not Java. In Java all resources can be accessed using the R class.
As you need to access the ids as well (for access to the Views), they are added to the R.java file.
So you're right. It's different from layout/menu/color/string resources. I guess that it's just due to the Java access.

Related

name garbaling in dll

I am using some functions in a dll but the only way I can get the name of the function to remain as I name it is to make it extern "c". If I do not do this then I have to copy the name from directly inside the dll and put the garbled text in my code, ed "someFunctionName" ends up "[email protected]@YAHXZ". It seems that every example I ever see dose not have this problem. Is there some setting I do not know about to force the linker to use the names I type without using a def file?
It was my understanding that this has something to do with C++ convention and cannot be changed, though I could be wrong on this point and if so, would also like to earn the answer.
Mean while if you are using functions from your DLL in your own code you can link to it "implicitly" (am I confusing the terms here?) by simply linking in the lib file compiler creates for the DLL and using the regular function names without all the garbage.
I think that what I am seeing is microsoft ("decoration") not from c++. I think the c++ name mangaling follows some rules that let it show the size of data being passed as arguments.
I do not want to link to it and use .lib etc because I do not want my main project to be entangled with the dll. I am trying to make a pluggin so it will be dynamically loaded with loadlibrary and getprocaddress. I am a bit new to this but it seems to work ok, I was just not sure how to use the def file properly. For example what are the rools regarding the order of names in the def as compared to the header file and what about variables, are they exported or do I have to have a function that returns a pointer to them.
Well some of MS help I encountered states that DEF files are obsolete, or at least MS is trying to make them so.
I didn't get deep in to the DLL rules my self but from what I understand it is sufficient to declare a function as _dllexport for it to be seen from the outside. If you want to specific ordinals (like in the plug-in case) that's another matter.
Variables can be exported and so are classes. I never tried using it, but the "hello world" example of a DLL that eVC 4 builds exports a function a class and a variable and does not use DEF file.
and after building that automatically generated code I get a dll with decorated function names (I view the dll in notepad to check). At first I could not figure out what was going on but after I put the decorated names into getprossaddres it works.

[Q] Html data parsing

Hi guys suddenly I have no experience with java and html parsing and I really need it...(possibly from http://www.uefa.com/teamsandplayers/teams/club=52280/domestic/index.html)
I want a simple way to convert an html website to xml document(fetch,convert,parse) or an easy alternative way to do it...
ps:if you know any alternative FREE resource of football(soccer) data tell it...
Android has built in several alternatives:
SAX Parser, XML Pull Parser and DOM.
A very good tutorial on all three of them can be found at IBM:
Working with XML on Android
I personally prefer the SAX Parser.
Of course you could just include another external parser, like HotSAX or many others via embedding external libraries.
In a small program I wrote I had to parse some html code, but the SAX Parser had problems with some German Umlauts. So I used TagSoup to clean the html and make a valid xml out of it. After that I could fetch the data with the SAX Parser.
thanks
wallla said:
Android has built in several alternatives:
SAX Parser, XML Pull Parser and DOM.
A very good tutorial on all three of them can be found at IBM:
Working with XML on Android
I personally prefer the SAX Parser.
Of course you could just include another external parser, like HotSAX or many others via embedding external libraries.
In a small program I wrote I had to parse some html code, but the SAX Parser had problems with some German Umlauts. So I used TagSoup to clean the html and make a valid xml out of it. After that I could fetch the data with the SAX Parser.
Click to expand...
Click to collapse
THANKS...maybe IBM example is good but a bit complicate for me(as i said i have no experience in parsing with java)...i prefer dom cause i get used to tree elements...
and if you can to publish some lines of source code with tagsoup(or refer me somewhere)...I NEED AN EXAMPLE
Here's a snippet of my program:
Code:
try {
URL url = new URL("http://www.url.com");
XMLReader xr = new Parser();
SAXHandler handler = new SAXHandler();
xr.setContentHandler(handler);
xr.parse(new InputSource(new InputStreamReader(url.openStream(), "ISO-8859-1")));
} catch (Exception e) {
}
You see, it's pretty simple...
The main part for "cleaning" the html-stuff is just this single line of code:
Code:
XMLReader xr = new Parser();
Parser() is of the type org.ccil.cowan.tagsoup.Parser;
If you want to use DOM, it should be quite similar.
Here's a basic example.

Stuck trying to get ActionBarSherlock working with SlidingMenu

Just as the title says. I am finally getting around to learning android development. I want to build a slick app that follows the newer android ux design guidelines. I found a SlidingMenu library and after some difficulty I actually got the basic functionality working. Now I want to make sure the user experience is the same all the way down to gingerbread devices, so I want to use ActionBarSherlock. There is very limited information for doing this. I add the library as a dependancy to the SlidingMenu library and change all the "extends __Activity" calls to "extends Sherlock__Activity". But now SlidingMenu won't build. I get a bunch of errors about
Code:
[2012-12-01 16:23:23 - SlidingMenuActivity] /home/jdonahue/workspace/ABS/res/values-v14/abs__styles.xml:4: error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Holo.ActionBar'.
[2012-12-01 16:23:23 - SlidingMenuActivity] /home/jdonahue/workspace/ABS/res/values-v14/abs__styles.xml:6: error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Holo.ActionBar.Solid'.
[2012-12-01 16:23:23 - SlidingMenuActivity] /home/jdonahue/workspace/ABS/res/values-v14/abs__styles.xml:8: error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Holo.Light.ActionBar'.
etc etc.
I should also mention I got ActionBarSherlock working by itself just fine. I just can't get SlidingMenu to work with it.
So, anyone know what's going on ? I am admittedly a beginner with android dev, so I'm sure I'm just doing something wrong. Just don't know what.

DataManagement Library for Easy Android Database Storage

Storing objects to a Database for an Android application should be fast and easy as:
Code:
dm.add(new StorableClass());
DataManagement is a new open source library that allows you to do just that.
DataManagement is a Java Android library designed to help easily and efficiently store aggregate classes to an SQLite database. It eliminates the need to write separate classes to manage database – object interactions and allows developers to use simple methods to store, query, update, and delete objects. The library is capable of storing all objects of classes whose instance variables are either primitive data types or are themselves objects of another storable class. The DataManagement Library condenses many standard database features into several simple methods. It is fully open source and the code can be found at http://epsilonlabsllc.github.com/DataManagement
Examples:
Creating a Storable Class:
Code:
public class StorableClass{
@Id
private int ident;
private int num1;
private double num2;
private String num3;
private boolean num4;
public static final int num5 = 3;
private OtherStorableClass[] ds2;
}
A storable class must meet two requirements. First, the class must have a private instance variable of type int that will be used as the id number of the object. This variable may be read by the application, but the application should not have the capability to write to or change this variable in anyway. This variable is identified by the system with an @Id annotation. In addition, the class should not have any instance variables that are not either primitive types, strings, or other storable objects.
Instantiating a DataManager Object:
Code:
DataManager dm = new DataManager(context);
The open method accepts the calling Context that is going to use the database. Usually this should be the calling Activity.
Opening a Database for Use:
Code:
dm.open();
This method must be called before the database is used in any way.
Closing a Database After Use:
Code:
dm.close();
This method should be called after all database operations have been performed.
Adding an Object to the Database:
Code:
int id = dm.add(new StorableClass());
The add method accepts an object of a storable class as its only parameter and adds it to the database. It returns its id in the database for future use.
Retrieving a Specific Item from the Database by ID:
Code:
StorableClass storableObject = dm.get(StorableClass.class, id);
The get method accepts two parameters: the data type of the stored object and the Id number of the object (the return value of the add method).
Retrieving All Objects of a Given Type Stored in the Database as a Collection:
Code:
storableObjectCollection = dm.getAll(StorableClass.class);
The getAll method’s only parameter is the class of the objects that should be retrieved.
Retrieving a Collection of Storable Objects that match a given criteria:
Code:
Collection<StorableClass> storableObjectCollection = dm.find(StorableClass.class, 5, "num1");
The find method accepts three parameters: the data type of the stored object, the value that is being searched for, and the name of the instance variable as a string. This method is overloaded in such a way that the second parameter may be any primitive value or a string.
Updating an Object in the Database:
Code:
dm.update(id, updatedObject);
The update method accepts two parameters: The id number of the object being updated and the updated object that will replace the existing one I the database. If the id number of the new object and the id number given as the first parameter do not match, the object’s id will be overwritten.
Deleting an Object by its Id number:
Code:
dm.delete(StorableClass.class, id);
The delete method accepts two parameters: The data type and id number of the object to be deleted.
Additional Notes:
Id numbers are used by the database to ensure that objects are put in the correct place and to allow the program to access these objects. It is important that programs using this library do not attempt to set these variables as they will be initialized and managed by the library. These id numbers are unique for objects of a given type; objects of different types may have the same id number. In addition, if objects are deleted from the database their id numbers are left empty and are not reused.
Licensing:
DataManagement is Currently Licensed under the GNU General Public License, version 3 (GPL-3.0). It is intended for open source use by anyone who would like to use it.
This is awesome!!
Tried it out for an app today-- incredibly simple! For those looking-- this library essentially replaces loads of SQL helper classes and queries with an interface that's similar to ArrayList.
Definitely going to use this for everything in the future!
Thanks
Did you change the license or something? The repo is no longer on github.
regaw_leinad said:
Did you change the license or something? The repo is no longer on github.
Click to expand...
Click to collapse
After a quick search on github, it looks like it's been moved here
https://github.com/epsilonlabsllc/DataManagement
cmike21 said:
After a quick search on github, it looks like it's been moved here
https://github.com/epsilonlabsllc/DataManagement
Click to expand...
Click to collapse
Thanks. I forgot to change it. I just edited my post with the correct url.
Sounds awesome! Great work.
Gonna try it this evening.
Anyone compared the performance with db4o?
are there any performance test with other DB libraries for android? and what about the this lib vs contentproviders?
activeandroid.com
code.google.com/p/orm-droid]orm-droid
satyan.github.com/sugar/
will definitly be using this once i learn some app development! thanks for this!
Just in time...
Hello,
I'm trying to build a simple project the test and learn how this lib works, but I'me quite new in programming and I have some difficulties to understand how to use dm.
The project will be a simple song database with edittexts for song and artist. I created the storableClass as the example, but I cannot understand how to connect it with the main activity, so I can use the output of the editTexts.
1st question is: do I need to have the String variables as private? I'm thinking that must have them as public, so I can connect them with the editTexts output.
2nd: question: all these methods needed to be called from storableClass, or from main activity, after I connected the storableClass with main activity? And how I do this?
Probably with the use of context you descibed, but I cannot understand how to do it. I tried sometimes but always get errors and a specific one "The constructor DataManager(Context) is not visible".
Is there any example project' source code which use this lib to get an Idea, or can you explain the context step more extensively?
Thanks in advance and sorry for noob questions.
dancer_69 said:
Hello,
I'm trying to build a simple project the test and learn how this lib works, but I'me quite new in programming and I have some difficulties to understand how to use dm.
The project will be a simple song database with edittexts for song and artist. I created the storableClass as the example, but I cannot understand how to connect it with the main activity, so I can use the output of the editTexts.
1st question is: do I need to have the String variables as private? I'm thinking that must have them as public, so I can connect them with the editTexts output.
2nd: question: all these methods needed to be called from storableClass, or from main activity, after I connected the storableClass with main activity? And how I do this?
Probably with the use of context you descibed, but I cannot understand how to do it. I tried sometimes but always get errors and a specific one "The constructor DataManager(Context) is not visible".
Is there any example project' source code which use this lib to get an Idea, or can you explain the context step more extensively?
Thanks in advance and sorry for noob questions.
Click to expand...
Click to collapse
Here is a sample project: https://github.com/epsilonlabsllc/D.../net/epsilonlabs/datamanagementefficient/test
(It's in the github project.)
You can set the strings on private, because you can grab the values of the edittext on your layout. Eclipse should generate your set/ get methods if you create your private strings. The methods. Take the values and insert them into your db, Look at the sample:
Code:
public DataSample(){
num1 = 3;
numderp = 3.0;
num3 = "three";
num4 = true;
ds2depier = new ArrayList<DataSample2>();
ds2depier.add(new DataSample2());
ds2depier.add(new DataSample2());
}
That is the basic constructor of the DataSample class. If you do an insert like
int id = dm.add(new StorableClass());
Click to expand...
Click to collapse
The basic constructor will be called and it sets your values for example the num1 =3. You could overwrite the basic constructor with your costum constructor to insert your values.
You activity call:
dm.add(DataSample(sSong,sTitle));
Click to expand...
Click to collapse
The constructor could be something like this:
public DataSample(String sSong, String sTitle){
sYourTitleDataBaseColumnCaption = sTitle;
sYourSongDataBaseColumnCaption = sSong;
}
Click to expand...
Click to collapse
Or use the set/get methods, my custom constructor are just an idea to show you an example. Just take a closer look at the github sample and it should work for you.
Thanks, I think I can figure it out now.
How to is very outdated. I can't initialize via new DataManager() but via getInstance(), also delete and update method doesn't have Id argument anymore.
Also,
I can't get this to work. I can't even add a member to collection because it needs to use db.add(new MyClass()); but i already have MyClass() initialized with their members. I have tried to do something like copy the Id from add, update into my other instance of this class and run a db.update() but it throws a RuntimeException.
Not usable at this time.
Sounds good!
I'll give it a try as soon as I start a new project that requires data storage ...
I really hate SQLiteOpenHelper, cursor and all this strange syntax ...
The idea is good, but it can't be compared to db4o, specially when talking about documentation.
Hello mate,
I'd like to use your library and backup the data with Google/Dropbox Sync... can you tell me the name of the file on which you save data?
Thanks,
Tiwiz

[LIB] NiceQL - makes database access easier

Let me introduce you my small library called NiceQL. It is free, open source and BSD-licenced.
It's main purpose is to make the process of creating databases easier. Hard-coding inside SQLiteOpenHelper is a no-go in my opinion. NiceQL gives developers a set of tools to create and manage database scheme, its tables, their columns and indices and preload seed data (data to be populated at first app launch). Library allows to generate database on a fly, load it from XML, use built-in SQL generators or use plain SQL (from XML too), you may also extend its objects or write new ones implementing Java interfaces.
Here's a quick code to start-up database with NiceQL and scheme in XML resource:
Code:
SQLiteDatabase db = new SchemeOpenHelper(this, "my_database", XmlScheme.parse(this, R.xml.sql_scheme)).getWritableDatabase();
The library is fully documented with examples on GitHub wiki. It does not handle database upgrades just yet, but this functionality will be implemented very soon.
I hope you will find it useful.

Categories

Resources