Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all 204402 articles
Browse latest View live

Changing a specific value in a list during runtime.

$
0
0

Hello everyone,

I have a simple Xamarin.Android-App.

On the Activity of this app, there is a list displayed. Please see following MyActivity.axml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android        ="http://schemas.android.com/apk/res/android"
android:orientation  ="vertical"
android:layout_width ="match_parent"
android:layout_height="match_parent">
<Button
    android:layout_width ="match_parent"
    android:layout_height="wrap_content"
    android:text         ="Click Me"
    android:layout_marginTop   ="20dp"
    android:layout_marginLeft   ="25dp"
    android:layout_marginRight   ="25dp"
    android:id="@+id/button" />
<Space
    android:layout_width="match_parent"
    android:layout_height="25dp"
    android:id="@+id/space" />
<ListView
    android:minWidth="25px"
    android:minHeight="25px"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/list" />
</LinearLayout>

One row of this list contains simply two entries, please see ListRow.axml:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"     
android:orientation="horizontal"     
android:layout_width="fill_parent"     
android:layout_height="fill_parent">        
    <TextView             
        android:id="@+id/name"            
        android:layout_width="wrap_content"          
        android:layout_height="wrap_content" 
        android:layout_marginLeft  ="5dp"
        android:layout_marginTop   ="10dp"
        android:layout_marginBottom="10dp"
        android:layout_marginRight ="5dp" />
    <TextView             
        android:id="@+id/value"            
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_marginLeft  ="5dp"
        android:layout_marginTop   ="10dp"
        android:layout_marginBottom="10dp"
        android:layout_marginRight ="5dp" />
</RelativeLayout>

So the code-behind of that activity looks like the following:

public class MyActivity : Activity
{
    List<Entry> List = null;

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        SetContentView(Resource.Layout.MyActivity);

        List = PopulateList();
        var lv = FindViewById<ListView>(Resource.Id.list);
        var adapter = new ListAdapter(this, Resource.Layout.List, List);
        lv.Adapter = adapter;

        FindViewById<Button>(Resource.Id.button).Click += OnButtonClick;
    }
}

For the sake of completeness, here is the code for my ListAdapter.cs-class:

class ListAdapter : ArrayAdapter
{
    List<Entry> List;
    public ListAdapter(Context Context, int ListId, List<Entry> List) : base(Context, ListId, List)
    {
        this.List = List;
    }
    public override int Count
    {
        get { return List.Count; }
    }
    public override View GetView(int position, View convertView, ViewGroup parent)
    {
        View v = convertView;
        if (v == null)
        {
            LayoutInflater inflater = (LayoutInflater)Context.GetSystemService(Context.LayoutInflaterService);
            v = inflater.Inflate(Resource.Layout.List, parent, false);
        }
        v.FindViewById<TextView>(Resource.Id.name).Text = List[position].Name;
        v.FindViewById<TextView>(Resource.Id.value).Text = "Original Value";
        return v;
    }
}

So my question now is the following: Assuming that there is more than one item within that List. On click of the button, I want to change one specific text within that list. Let's say of the second entry in the list the (Resource.Id.value).Text (which now says "Original Value") to "Changed Value" or something like that. But only of the second one. All the other items should stay the same.

Please see following scenario, maybe it's easier to understand what I am trying to do:

NameValue
Item Number 1Original Value
Item Number 2Original Value
Item Number 3Original Value

[Button Click]

NameValue
Item Number 1Original Value
Item Number 2Changed Value
Item Number 3Original Value

Can anyone maybe help me / tell me how to do this? What does my private void OnButtonClick(object sender, EventArgs e)-method have to look like? How can I access a single entry in that list?

Thanks in advance for all answers and best regards


HowTo: ZXing.Net.Mobile with PRISM

$
0
0

Hy,

i want to integrate Barcode Scanning inn my App using Prism.
<br /> private async void Scan()<br /> {<br /> var options = new MobileBarcodeScanningOptions<br /> {<br /> AutoRotate = true,<br /> UseFrontCameraIfAvailable = false,<br /> TryHarder = true,<br /> PossibleFormats = new List&lt;ZXing.BarcodeFormat> { ZXing.BarcodeFormat.CODE_128 }<br /> };</p> <pre><code>var scanPage = new ZXingScannerPage(options) { DefaultOverlayTopText = "Align the barcode within the frame", DefaultOverlayBottomText = string.Empty, DefaultOverlayShowFlashButton = true }; await Navigation.PushAsync((scanPage); scanPage.OnScanResult += (result) => { // Stop scanning scanPage.IsScanning = false; // Pop the page and show the result Device.BeginInvokeOnMainThread(async () => { await NavigationService.GoBackAsync(); await _dialogService.DisplayAlertAsync("Barcode Scanned", result.Text, "OK"); }); };

}

My problem is the line
<br /> await Navigation.PushAsync((scanPage);<br />
I do not have access to Navigation on PRISM and the PRISM NavigationService wont take a page as parameter.

Has anyone solved this issue?

Thank you

How to use customized view component from library?

$
0
0

Hi all.
I want to embed a gauge (or clock) in my application.
So After a search I found this:
github.com/Pygmalion69/Gauge
Looks good.
How can I use this component in my xamarin.android project?

Cannot keep ListView ordered/sorted when navigating away and back

$
0
0

Hello!

I'm learning the ListView control and sorting data it shows, but i can't seem to fix a scenario.
I am using Visual Studio 2017 Community.

I am trying to have a list always ordered by this criteria:

  • column create date (DateTime.Now)
  • order descending

The following 3 scenarios must work with the same order criteria applied, but i can't seem to make it work for the 3rd one.
1) (working) When i open the app the 1st time (done with sorting in overriden Init method
2) (working) When i add items in the list (enter/done/verify on a specific Entry control adds to my ListView an item)
3) (not working) When, while the app is running , i navigate to another Page and back to the one that keeps this ListView

1) was solved with overriding Init method of the viewModel (which keeps the ObservableCollection prop)
2) was solved by using ObservableCollection.Insert(,item) instead of ObservableCollection.Add()
3) In the view, i tried overriding OnAppearing

In XAML:
<ListView
x:Name="ItemListView"
ItemsSource="{Binding Items}"
CachingStrategy="RecycleElement"

            HorizontalOptions="CenterAndExpand"
            VerticalOptions="CenterAndExpand"

            >
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout
                            Spacing="10"
                            Orientation="Horizontal"
                            >
                            <StackLayout>
                                <Label
                                    Text="{Binding Code}"
                                />

                                <Label
                                    Text="{Binding Description}"
                                />
                            </StackLayout>

                            <Label
                                Text="{Binding Number}"
                                FontAttributes="Bold"
                                VerticalOptions="Center"
                            />
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

In code-behind of View:

protected override async void OnAppearing()
{
base.OnAppearing();
await _itemViewModel.SaveItem(); //does some SQLite work related to Items
_itemPageViewModel.SortItems();
ItemListView.ItemsSource = _itemViewModel.Items;
}

In View-Model:
internal void SortItems()
{
Items.OrderByDescending(x => x.CreateDate);
}

However, when i repeatedly exit the Page and reenter, the items are unsorted.

XF image tapgesturerecognizer not working on UWP?

$
0
0

xamarin forms image tapgesturerecognizer not working on UWP, working fine on Android. How to fix it? Thank you!

is it possible to implement NFC in xamarin forms?

$
0
0

I have been trying with sample plugin but i am not able to figure out how to implement NFC read/Write for Android/iOS using a plugin.if it is possible share some sample code which would help me

How to do this type of dynamic layout and view/page-navigation ?

$
0
0

Hello guys, I'd appreciate some help from some more experienced Xamarin developers. I've worked quiet alot in wpf before, but this is my first big Xamarin project and I need a good base structure for navigating pages and subviews in it.

What I need to do

  • Have a way to navigate in the top or bottom view of the application (top covers 30% and the bottom covers about 70% of the screen) and change content depending on the user actions. I.e. the top part of the screen might show a picture or a map with GPS or switch between, while the bottom part shows information regarding the map and can change to another view to show more specific information and so on. Basically both the top and the bottom need to be able to change subviews.

I'd like an easy way to navigating subviews in a dynamic way.

My thoughts so far.

  • One way I was thinking is to make something more custom as a BaseMainPage, which holds a grid that splits the screen like I want it. Then I just change the content of the grid depending on user action. The problem as I see it is that I will need to write my own navigation for this and keep track of stuff.
  • The other way to use the NavigationPage to simply switch the whole page each time, both the top and the bottom. But I dont wanna create a new map object each time, so to avoid this, I think this is a pretty bad option. Or can I get around this, reusing the same map somehow?

Xamarin Live Player with Forms 3.1.0583944 and FlexLayout

$
0
0

Can someone confirm here that FlexLayout is not supported on Xamarin Live Player (beta V1.5.196 (696)).

I am getting this error.

Position 7:6. Type FlexLayout not found in xmlns http://xamarin.com/schemas/2014/forms          

Dependent project myProject.csproj failed to build, using old version.          

how can l connect my xammarin forms application to sql online database

$
0
0

I am trying to make a xamarin forms application which perfom crude operations using sql server online so guys l wanted your help ,on how can l connect and add,update,view and delete items from the sql server using xamarin forms,if you have the source code l will greatly appreciate that

A resource with the key 'Xamarin.Forms.StackLayout' is already present in the ResourceDictionary

$
0
0

Hello everyone, I am getting the following Exception:
System.ArgumentException: A resource with the key 'Xamarin.Forms.StackLayout' is already present in the ResourceDictionary.

Because of this code in my App.xaml ResourceDictionary:

<Application.Resources>
        <ResourceDictionary>
            <!-- omitted irrelevant parts -->

            <Style TargetType="StackLayout" x:Key="VerticalStack">
                <Setter Property="Orientation" Value="Vertical"/>
                <Setter Property="Spacing" Value="16"/>
            </Style>

            <Style x:Name="FormFirstPortraitStyle" TargetType="StackLayout" BasedOn="{StaticResource VerticalStack}">
                <Setter Property="HorizontalOptions" Value="Center"/>
                <Setter Property="VerticalOptions" Value="Start"/>
                <Setter Property="Margin" Value="16, 100, 16, 16"/>
            </Style>

            <Style x:Name="FormFirstLandscapeStyle" TargetType="StackLayout" BasedOn="{StaticResource VerticalStack}">
                <Setter Property="HorizontalOptions" Value="Center"/>
                <Setter Property="VerticalOptions" Value="Center"/>
                <Setter Property="Margin" Value="16, 16, 16, 16"/>
            </Style>
        </ResourceDictionary>
    </Application.Resources>

If I remove the "FormFirstLandscapeStyle" style, it works.
I am setting the TargetType to StackLayout, not the key... I think I am doing something wrong, but I cannot figure out what...
Thanks for helping.

AppCenter Push notification implementation

$
0
0

Hi guys,
I'm trying to work out how to implement push notification with AppCenter. I followed the instructions for each platform (iOS, Android and UWP) but there are some issues.

  • Android: I added Microsoft.AppCenter.Push, in the AndroidManifest what I found in the AppCenter instruction and add google-services.json. After that I'm receiving the following error.

Java.Lang.RuntimeException: String resource ID #0x7f09001a

<application android:label="MyApp.Android">
    <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
    <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="${applicationId}" />
        </intent-filter>
    </receiver>
</application>

What is the correct implementation? How can I display then a Toast?

  • UWP: I received the message from AppCenter but how I can display a message? What is the implementation if the app is closed?
  • iOS: is there an implementation that I can follow?

Thank you guys in advance!

TabbedPage event on tab click or refresh tab when same tab is clicked?

$
0
0

I'm using a TabbedPage with Xamarin.Forms, and when a user is already on Tab 2, and clicks on Tab 2, I'd either like that tab to reload, or i'd like to run my own custom code to refresh the page.

I have been trying to find any sort of event I could hook into, or a way to do this with custom renderers but have been unable to find anything. What's the simplest way to do this?

Thanks!

Parsing JSONString

$
0
0

Hi
I have trouble parsing my JSONstring retrived from my url.
below is my JSONString
php_resp = "{\"customer\":\"turkerler\",\"authority\":\"1023\",\"url\":\"http:\/\/gultekinteknik.com.tr\/file\/TURKERLER-LOGO1.png\",\"message\":\"Welcome\"}"

I need your urgent help guys! Thanks in advance.

Scandit vs. Manatee Works Barcode scanner component

$
0
0

Does anyone have experience with both Scandit and Manatee.

I've tested Scandit and so far I really like the performance and have not tried Manatee yet, but plan on doing so in the next few days. However both are rather pricey and would appreciate any feedback others have had with one or both of these tools.

Thank you in advance.

arm support for 8.0 and up?

$
0
0

While trying to build the default Xamarin.Forms xaml app ("Welcome to Xamarin.Forms!") I encountered the following oddity:

Where is the ARM support for 8.0 (and up)? Isn't this going to be a problem for apps destined for ARM devices?


Getting screen contents height

$
0
0

Hello, I am trying to create my own pan and pinch gestures so I can understand how they work, however I am having some problems finding the boundaries for the dragging. I currently use the ScreenHeight and Contents.Height to find boundaries, however I believe having tabs and a navigation bar are affecting my panning, to where I can't pan all the way to the bottom. Is there a way to get the "usable" content heights that the user sees? I don't care for the tabs and navigation.

Page push -> flickering / blinking on dark background

$
0
0

Whenever one changes the page while using a dark background or the dark theme the screen flickers white once.
I tried it in a personal application from a Navigation page with await PushAsync aswell as on the MasterDetail Template with just the dark theme applied.

Giving epileptic episodes on every Page change isn't a option and a light theme isn't popular on the android world. Does someone have a solution to this?

Tested on android & uwp. Android with background and theme, uwp with a dark background.
GIF of the UWP: https://gfycat.com/WeeJaggedAgama

EDIT: It shouldn't matter since the theme also doesnt work but here is the change that is done to the App.xaml to get the dark background shown in the gif

         <Color x:Key="DARK_Background">#1a1a1a</Color>

                <Style TargetType="ContentPage" ApplyToDerivedTypes="True">
                    <Setter Property="BackgroundColor" Value="{StaticResource DARK_Background}" />
                </Style>

Unable to use AOT when compiling in VSTS

$
0
0

I'm using continuous integration with Microsofts VSTS but if I enable AOT compilation I get the following error:

Java.Interop.Tools.Diagnostics.XamarinAndroidException: error XA5101: Missing Android NDK toolchains directory '\toolchains'. Please install the Android NDK. [d:\a\1\s\Mobile4Projects\Mobile4Projects.Droid\Mobile4Projects.Droid.CN.csproj]

Turning AOT off resolves the issue.

I'm using the Xamarin.Android build component (https://www.visualstudio.com/en-gb/docs/build/steps/build/xamarin-android)

Does anyone have any suggestions to fix this?

How to monitor he Bluetooth Connectivity state changes from Xamarin.Forms

$
0
0

Need to check the bluetooth connection to a remote device exists or got disconnected. Its basically a Forms which mainly targets Android and UWP.

I tried with the Dependency services and made the implementation in Android as below,

_[assembly: Xamarin.Forms.Dependency(typeof(BluetoothListenerActivity))]
namespace demotool.Droid
{
public class BluetoothListenerActivity : Activity,IBluetoothListener
{
public event EventHandler OnDeviceDisconnected;
public static BluetoothListenerActivity mySelf;

    //string device;
    public void start()
    {
        mySelf = this;
        BluetoothStatusBroadCast mreceiver = new BluetoothStatusBroadCast();
        IntentFilter mfilter = new IntentFilter(BluetoothDevice.ActionAclDisconnected);
        Forms.Context.RegisterReceiver(mreceiver,mfilter);
    }
    public void receivedstatuschangd(string devicename,string state)
    {
        OnDeviceDisconnected(this, new DeviceDisconnectedEventArgs(name: devicename,status: state));
    }
}

}_

BroadcastReceiver:
namespace Demo.Droid
{
[BroadcastReceiver]
class BluetoothStatusBroadCast : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
BluetoothDevice device =(BluetoothDevice)intent.GetParcelableExtra(BluetoothDevice.ExtraDevice);
BluetoothListenerActivity.mySelf.receivedstatuschangd(device.Name, intent.Action);
}
}
}

Xamarin Forms Part:
_ protected override void OnStart()
{
IBluetoothListener bluetoothlistener = DependencyService.Get();
bluetoothlistener.start();
bluetoothlistener.OnDeviceDisconnected += Bluetoothlistener_OnDeviceDisconnected;
}
private void Bluetoothlistener_OnDeviceDisconnected(object sender, DeviceDisconnectedEventArgs e)
{
Page page1 = new Page();
page1.DisplayAlert(e.Name+ " " +e.Status, "Alert", "OK");
}_

The Intent Action that I have registered- BluetoothDevice.ActionAclDisconnected, is getting triggered once the Pairing is completed or a connection request is made, which I assume is not the actual Disconnection of the devices

Is there any common plugin which monitors the Bluetooth Connectivity Changes to a remote device. Or could you please tell me the actual Intent Action that I should listen for.

Thanks in Advance !

Want to design a UI according to the photo that is attached.

$
0
0

Can i merge two pages such as content page and tabbed page?

Or is there any other solution please let me know.

Viewing all 204402 articles
Browse latest View live