I am new to Unity and grabbed the BootCamp project and ran it within Unity 4.1.5f1 as a Windows Build without any modification
I then tried to build to Android and had a bunch of errors (mostly variables not being declared)
But I have one remaining that I just don't understand...
In the following code in the file ImageEffectsOrder.js the javascript references an order method of the array sorted[] as sorted[i].order
The compiler errors with 'order' is not a member of object.
So I'm a little confused as to why the windows build supports this member but not android.
This makes me wonder what other surprises await when converting from platform to platform.
But for now can anyone point me to a workaround for the order member? And I'm not quite clear on what it is actually returning...it seems the variable i should give you the order.
The order just seems intrinsic from the code, it is never set to any value, so what 'order' is it? I can't seem to find any docs on this 'member' of the Array class.
Here is the code:
var sorted : Array = new Array();
var i : int = 0;
for (var fx : PostEffectsBase in GetComponents(PostEffectsBase))
{
if(fx && fx.enabled)
{
sorted[i++] = fx;
}
}
while (sorted.length)
{
var indexToUse : int = 0;
var orderValue : int = -1;
for(i = 0; i < sorted.length; i++) {
if(sorted[i].order > orderValue) {
orderValue = sorted[i].order;
indexToUse = i;
}
}
...more code...
I solved it. The problem is not with the Array Class as the fx that is being assigned to the sorted[] array is an object of class PostEffectsBase.
So the actual problem is one of casting when we try to use sorted[i].order
I changed the reference from sorted[i].order to (sorted[i] as PostEffectsBase).order and it worked.
I have to remember this. It seems there are a lot of these casts that have to be done between platforms.
Related
So I was hoping to make a list/array of textviews so that I can iterate a loop and set the .text value of the TextViews as I go. Otherwise I would have to set the values in the code statically which would be a whole lot messier and potentially not even feasible for my needs.
So in the code below the idea would be to iterate the loop and when the correct value is confirmed that [index] would then set the corresponding
var refillToken : Double = (0).toDouble()
var tweetStored : BooleanArray = BooleanArray(20)
var tweetActive : BooleanArray = BooleanArray(20)
var userID: MutableList<String> = mutableListOf("")
var textViewToken = 0
while (refillToken > 0) {
var token: Int = 0
while (token < (tweetStored.size)) {
if (tweetStored[token] == true) {
tweetActive[token] = true
textView[textViewToken].text = userID[token]
textViewToken++
refillToken--
token++
if (refillToken < 0) {
break
}
}
}
}
}
I know my loop is probably messy by sane people standards but it makes sense to me and (hopefully) isn't the issue at play. Have found a few articles or ideas searching for the past two hours but they're either 10 years old (and I think deprecated), for java or don't work for whatever reason.
You need to get a value and then add it to the textview and change this value after every action on the page.
Use variable assignment for this task
I'm trying to create a line chart in Android using MPAndroidChart Library and as entries I have values like 1200.10, 1300.70 and so on, but on my chart the values are rounded (1200, 1301), and I want to display the original values. How can I do that? I tried different solutions but couldn't solve the problem yet. I'm using the Kotlin language. Thanks!
for (item in reversedCashList) {
if (i <= daysNmb) {
var cashValue: String = transformDataForChart(item.value!!)
dataValsEntries.add(Entry(i, cashValue.toFloat()))
i++
}
}
Also, I'm using this formatter Class to format my values because the initial format is like 120.200,10 and I changed them to 120200.10 but this values is displayed as 120200. My Formatter Class:
private fun transformDataForChart(totalValue: String): String {
return if (totalValue.contains(".")) {
val test = totalValue.replace(".", "")
test.replace(",", ".")
} else {
totalValue.replace(",", ".")
}
}
You can try with BigDecimal, something like BigDecimal.valueOf(X).setScale(decimalPlace(usually 2), BigDecimal.ROUND_HALF_UP).floatValue()
The idea is that float cannot hold so many values as the Double, I've encountered this issue as some point as well, and I had to change everything to Double just to make it more easier to maintain... Therefor I don't think is a straight-forward method to keep everything you need in the float format.
I'm trying to use the Indexed access operator as it explained in the following link:
Indexed access operator
It is written there that it works exactly as set & get but code isn't compiled when trying for example to compile the following:
var vv : Array<Int> = Array(6 ,{ 5*it })
vv[1, 4] =5
that is exactly like the pattern in the link:
a[i, j] = b a.set(i, j, b)
After reading comments I understand that a[i,j] means setting a value to two dimensional array, but still the following code doesn't work:
val rows = 3
val cols = 4
var arr = Array(rows) { IntArray(cols) }
arr[2,3] = 5
I'm attempting to get the int resource id for a layout resource by name, using Resources.GetIdentifier() of the Android API, but it returns 0. I'm using c#/monodroid/Xamarin, but regular java Android knowledge would apply too I suspect. Here's my code:
int resId = Resources.GetIdentifier(typeName, "layout", _activity.PackageName);
Where typeName = "FrmMain", and in my project I have the file "Resources/Layout/FrmMain.axml". Any ideas?
This is old, but for everyone getting this problem, I think it is because the resource name should be in lower case, so:
int resId = Resources.GetIdentifier("FrmMain", "layout", _activity.PackageName);
does not work, but:
int resId = Resources.GetIdentifier("frmmain", nameof(Resource.Layout).ToLower(), _activity.PackageName);
should work
I don't know why that's failing, but wouldn't something like Resource.Layout.FrmMain achieve what you're after?
edit:
According to this answer, you can (and should) use reflection to achieve what you're after, so I think you would try something like this:
var resourceId = (int)typeof(Resource.Layout).GetField(typeName).GetValue(null);
which does seem to work on my app and should get what you're after.
In my case, this issue came up when I had to upgrade the target SDK due to google's new policy since November, 2018.
I had to display some strings according to the server response code (ex : api_res_001_suc), but it did not work on the upgraded version.
The overall version, about 22 as I recall, had to be changed to 27.
The cause of the issue seems to be the default translation stuff. When I put all the default translation for every string, it worked.
My code is,
getResources().getIdentifier(resName, "string", "packageName");
I've created a ResourceHelper class to handle this situation. Here is the code:
public static class ResourceHelper
{
public static int FindId(string resourceId)
{
var type = typeof(Resource.Id);
var field = type.GetField(resourceId);
return (int)field.GetRawConstantValue();
}
public static int FindLayout(string layoutName)
{
var type = typeof(Resource.Layout);
var field = type.GetField(layoutName);
return (int)field.GetRawConstantValue();
}
public static int FindMenu(string menuName)
{
var type = typeof(Resource.Menu);
var field = type.GetField(menuName);
return (int)field.GetRawConstantValue();
}
}
Actually I'm improving it because I need to use it from another Assembly and it's restricted to work in the same Assembly of the Droid App. I'm thinking about put a generic method (or an Extension one) to do this. Here is a draft of my idea:
public static int FindResource<T>(string resourceName)
{
var type = typeof(T);
var field = type.GetField(resourceName);
return (int)field.GetRawConstantValue();
}
Hope it can help you.
I want to work dynamically therefore I want to bind text views dynamically I think an example would explain me the best
assuming I want to bind 7 image views i can do it like this :
Country = (EditText)findViewById(R.id.CountryEditText);
City = (EditText)findViewById(R.id.CityEditText);
LivinigCreture = (EditText)findViewById(R.id.LivingCretureE);
Nature =(EditText)findViewById(R.id.NatureEditText);
Inanimate = (EditText)findViewById(R.id.InanimateEditText);
KnowenPersonality = (EditText)findViewById(R.id.KnowenPersonalityEditText);
Occupation = (EditText)findViewById(R.id.OccupationEditText);
but lets change 7 with NUMOFFILEDS as a final where i want to do the previous ?
myImages = new ImageView [7];
for (int i = 0; i<7;i++,????)
myImages[i] = (ImageView)findViewById(R.id.initialImageView01);
notice : in my R file the R.id.initialImageView01 - R.id.initialImageView07 are not generate in a cont gap between them therefore I don't know how to make this architecture possible .
and if there's a way can someone show me an example how to work dynmiclly (like using jsp on android combined way or something ?)
id its possiable to do so constant times is it possible to build an the same xml constant num of times like jsp does
thank u pep:)
You can store the IDs themselves in an array at the beginning of your Activity; that way you'll only need to write them once and you can index them afterwards.
Something like:
int[] initialImageViewIds = {
R.id.CountryEditText,
R.id.CityEditText,
R.id.LivingCretureE,
R.id.NatureEditText,
R.id.InanimateEditText,
R.id.KnowenPersonalityEditText,
R.id.OccupationEditText
};
Then you can access them with:
myImages = new ImageView [7];
for (int i = 0; i<7;i++) {
myImages[i] = (ImageView)findViewById(initialImageViewIds[i]);
}
If that's not enough and you really want to get the IDs dynamically, I suppose you can use reflection on the R.id class, possibly with something like R.id.getClass().getFields() and iterate on the fields to check if their names interest you. Check reference for the Class class, too.