In Xamarin Android, I need to store some value in global variable which can be use through out the activities.
So how can i set and get the global variable?
I think you could use SharedPreferences.
For example, set data:
var data = GetSharedPreferences("Data", 0);
var editor = data.Edit();
editor.PutString("name","ABC");
editor.Commit();
And get data:
var data = GetSharedPreferences("Data", 0);
string name = data.GetString("name", "default");
And I think you could also try to use Application and Resource.
Create a static class and a static variables in there.
Related
We need to add service information like officeId for entities.
Or how we can use IntuitAnyType for set and get our service information. I tried to add xmlElement into IntuitAnyType, and then create bill, but when I try to get this bill, IntuitAnyType field (BillEx) was null. Also I tried to add NumberTypeCustomFieldDefinition and got Validation Exception was thrown.Details:Operation Could not find resource for relative : /v3/company/4620816365019493550/numbertypecustomfielddefinition of full path: https://c50.sandbox.qbo.intuit.com/qbo50/v3/company/xxxxxxxxxxx/numbertypecustomfielddefinition?minorversion=29&requestid=a52a148d0f6f4c3ab366f55ca7440525 is not supported..
var dataService = new DataService(_serviceContext);
var officeId= new QBO.NumberTypeCustomFieldDefinition()
{
DefaultValue = 0,
DefaultValueSpecified = true,
Name = "OfficeId",
Hidden = true,
EntityType = QBO.objectNameEnumType.Bill.ToString(),
Required = false
};
var createdCaseIdField = dataService.Add(caseId);
is it possible?
Is there a way to create and update hidden custom field for bill with use api
No. Custom fields can only be created via the UI, and they are visible in the UI.
This is all documented here:
https://developer.intuit.com/app/developer/qbo/docs/develop/tutorials/create-custom-fields#enable-custom-fields
I am working on passing data from a View to a Page, to be more exact from RecetasView to RecetaView, showing the data in RecetaView works just fine using {Binding} in my xaml file, but i want to get the same data in C#.
The way I'm sharing the data:
RecetasView.xaml.cs
var selectedItem = e.Item as RecetasModel;
var recetaView = new RecetaView();
recetaView.bindingContext = selectedItem;
await Navigation.PushAsync(recetaView);
This is what I have tried to get the data:
RecetaView.xaml.cs
var receta = this.BindingContext;
But this crashes my app.
I can't really tell what's the error, because for some reason I can't debug the app in my device, I'm doing this on release.
Is there any other way to get the shared data in C#?
The property BindingContext is of the type object and hence when you get it from the property the RecetasModel data is actually of the type object and hence you need to cast it to the exact type before using it
var receta = this.BindingContext as RecetasModel;
if(receta != nulll)
{ //use receta }
you need to properly cast BindingContext
var receta = (RecetasModel)this.BindingContext;
actually Im working on an Upload-Bot for Discord. My problem is I wanna use a variable (that contains a api permalink) as a Hyperlink markdown.
At the moment it looks like this:
But it should look like this: (The "Vale Guardian" Hyperlink mardown should contain the permalink from the "DpsReportVg" variable)
using (WebClient client2 = new WebClient())
{
DpsReport1 = client2.DownloadString("https://dps.report/getUploads?json=1&userToken=5656165565161312564651635");
}
var dataObject = JsonConvert.DeserializeObject<dynamic>(DpsReport1);
string DpsReportVg = dataObject.uploads[3].permalink.ToString();
var embed = new EmbedBuilder();
embed.WithTitle("DPS-Reports uploaded by ");
embed.WithDescription(Context.User.Username);
embed.WithColor(new Color(0, 255, 0));
embed.WithCurrentTimestamp();
embed.AddField("Spirit Vale", "[Vale Guardian](DpsReportVg)");
You almost had it, but you're overlooking a minor detail.
You have
embed.AddField("Spirit Vale", "[Vale Guardian](DpsReportVg)");
But what you should have is
embed.AddField("Spirit Vale", $"[Vale Guardian]({DpsReportVg})");
Explanation:
You aren't actually using your variable, you are just adding a String that happens to match your variable name.
My edit to your code uses string interpolation to insert your variable into your string thereby providing the actual link that you have stored in the variable.
You need to use the EmbedBuilder.withUrl method:
Check out the official docs for a complete example with images:
https://discord4j.readthedocs.io/en/latest/Making-embedded-content-using-EmbedBuilder/
I'm developing for WP8 and I need to store custom app settings. I found func 'ApplicationData' but it's not supported in WP8. Can you help me? I want to store permanent variables provided by user. For example:
Country = UA
News = 1
etc.
You can use Isolated Storage or ApplicationData.LocalSettings like this :
var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
// Create a simple setting
localSettings.Values["exampleSetting"] = "Hello Windows";
// Read data from a simple setting
Object value = localSettings.Values["exampleSetting"];
if (value == null)
{
// No data
}
else
{
// Access data in value
}
// Delete a simple setting
localSettings.Values.Remove("exampleSetting");
Check this Link and also this Link
I am currently making a program (C# .Net 4) that has multiple options, which are saved to a file.
These options are their own variables in-code, and I was wondering if there was a way to get the variables and values of these options dynamically in code.
In my case, I have these options in a "Settings" class, and I access them from my main form class using Settings.varSetting.
I get and set these variables in multiple places in code; is it possible to consolidate the list of variables so that I can access and set them (for example, creating a Settings form which pulls the available options and their values and draws the form dynamically) more easily/consistently?
Here are the current variables I have in the Settings class:
public static Uri uriHomePage = new Uri("http://www.google.com");
public static int intInitOpacity = 100;
public static string strWindowTitle = "OpaciBrowser";
public static bool boolSaveHistory = false;
public static bool boolAutoRemoveTask = true; //Automatically remove window from task bar if under:
public static int intRemoveTaskLevel = 50; //percent
public static bool boolHideOnMinimized = true;
Thanks for any help,
Karl Tatom ( TheMusiKid )
You might want to consider using the Application Settings features built into the framework for loading and storing application settings.
var dict = typeof(Settings)
.GetFields(BindingFlags.Static | BindingFlags.Public)
.ToDictionary(f=>f.Name, f=>f.GetValue(null));
read about reflections:
http://msdn.microsoft.com/en-us/library/ms173183%28v=vs.100%29.aspx