While using Dot42 it appears that I can access AddPreferencesFromResource(int) of PreferenceActivity class but the resource that gets passed to this method is not available to me. I expected the call to look like AddPreferencesFromResource(R.Xmls.Preferences), however R.Xmls does not exist. The xml folder contains preferences.xml and is stored next to layout, menu, etc. resource folders. However generated R.cs doesn't contain a class for Xmls. Included sample projects don't have any examples of usage of PreferenceActivity. Can anybody confirm whether or not preferences are supported in Dot42?
Your question is probably not so much how to populate a preference fragment from XML but more how to add an XML resource to a dot42 project and how to reference it.
You add an XML resource by adding an XML file to your Visual Studio (dot42) project as you would normally do; this is no different from adding an XML file to a non-dot42 project. Next, go to the properties of the file and set BuildAction to XmlResource.
Note that dot42 has no folder structure requirement (such as /res/xml/).
When you now compile again and type "R." you will see intellisence coming up with R.Xmls.
If you take a look at R.cs (under Properties), you will see it now includes R.Xmls with a generated member for your XML resource:
//------------------------------------------------------------------------------
// This file is automatically generated by dot42
//------------------------------------------------------------------------------
namespace PreferenceFragmentSample
{
using System;
public sealed class R
{
public sealed class Layouts
{
public const int MainLayout = 0x7f020000;
}
public sealed class Xmls
{
public const int preferences = 0x7f030000;
}
}
}
Related
I have a desktop application that produces resource / data files for my android app. These are XML text files that store instances of my custom data class. These objects are serialized using the Simple XML Serialization library. In my android app, I'd like to instantiate objects from this XML serialization class.
I like to add these xml files to Android Studio so they are included in the APK on device install and are placed, for example, in the private app directory "files", to which getFilesDir() is mapped. I can't find a way to do that.
If I add these xml files to the Android XML resource folder, I need to use Android's XML resource parser, and can not use the Simple XML library.
Any tips? I feel I made a wrong design choice seeing how restrictive the resource bundling is.
Thanks, Kind regards,
Harmen
As per CommonsWare's comment: the solution was adding it to the raw resource folder, then you can access it using:
InputStream xmlExerciseInputStream = getResources().openRawResource(R.raw.myresource);
MyClass myClass = serializer.read(MyClass.class, xmlExerciseInputStream);
screenshot of layout file Link of the screen shot click here
FoodItemBinding.java file is generated by compiler , how the public class name and file name is different here, also i m not able to change it.
Check the Screenshot Attched
error: class FoodItemBinding is public, should be declared in a file named FoodItemBinding.java
public final class FoodItemBinding implements ViewBinding {
^
Name the layout file food_item.xml instead of fooditem.xml
ViewBinding generates the java file as FooditemBinding but the class is still named FoodItemBinding, hence the issue of class name.
For some unknown reason, android studio decided not to recognize the .java file. Any idea how to resolve this?
I've tried deleting the file and recreating it, but it still results in the same issue. When recreating the file, some error came up and the file is automatically recreated
public class SubmitDealAsyncTask extends AsyncTask<Void, Void, String> {
...
}
It turns out that there's a wrong file association entry which associate that particular filename as a JavaFX file.
Look in the Preferences > Editor > File Types under Java files, the name of SubmitDealAsyncTask.java file is there and all I needed to do is to remove it.
Check your java file name and Class name.
class SubmitAsyncTask {}
should be saved in "SubmitAsyncTask.java"
Go to Preferences > Editor > File Types > Java, and then under each of the listed file types (Yes, unfortunately you have to look through all of them), and scroll down at the bottom of the to see if there is an entry for you file, and then click on it and the click the - sign.
How did you include this file? I had problems just copying java classes in Android Studio, so maybe you might want to create a new java class and copy the content of the desired file into it. Then there should be no problem.
Try to copy all the code from this file and paste it inside your package(where you paint over you name with blue lines).
Android Studio will create new .java file for you there.
#root I created the class by right clicking on the package folder(com.example.tttt) in the project view and then new java class and naming it SubmitAsyncTask and then using the prototype you provided to create a dummy class and it worked for me as you can see below so if this doesn't solve it then you are missing something in the code its no longer an IDE problem :
This may sound like a question asked by another user, but the solution does not work for me so I would like to try asking about my code.
I have created a folder under the res directory that contains some java classes I would like to reference/ call from one of my Activities but the import does not work and the classes do not seem to be recognised.
Calling code in the Activity file:
// Method to populate the screen with images
public void initializeWithCGImages(){
ArrayList<src.cercia.batik.app.DesignUnitViewer> mapviewers,viewerList;
ArrayList<src.cercia.batik.geometry.Population> populations;
src.cercia.batik.app.InitializePopulation initialize=new src.cercia.batik.app.InitializePopulation();
populations = initialize.getInitialGenes();
mapviewers=new ArrayList<cercia.batik.app.DesignUnitViewer>();
...
}
Code for the reference in folder: "res/src/cercia/batik/app":
package cercia.batik.app;
import cercia.batik.geometry.Population;
public class InitializePopulation {
public InitializePopulation(){
}
...
}
The res directory is for resources. Things like imaged and layouts. The compiler isn't going to look there for Java files. Move them up into your java folder.
I'm creating an Android Library Project, and I have a class in which the programmer has to pass an R.layout.some_layout, to the instance, in which some view should have an #+id/text
So the idea is that I create an XML layout file, I add a view with an "text" as its ID, and after I instantiate the class I use object.setLayout(R.layout.some_layout);
In the definition of the class there is something like this:
public void setLayout(int layoutId) {
View view = findViewById(R.id.text); // error here cause of the R.id
}
The problem is that since it's a library project, my R.java doesn't have an R.id, so it marks an error on that line. Any ideas of how to do this?
There must be an error in one of your xml file
Kindly check your xml may be some syntax error remain with the xml file which is preventing to create complete R.java
Then
Clean & Rebuild your project and also you can Restart IDE if problem remains
Did you check if your R.java file was generated correctly? If not, please clean build your library project and check again.