locked
refresh listview from thread RRS feed

  • Question

  • User325526 posted

    Hi, i have a thread with barcode and when scan i need send the code to my listview and always refresh when recevei another barcode, but i don't know how to do, someone can help me?? Thanks

    This is my thread:

    if (barcode.Length > 0)
                                        {
                                            System.Diagnostics.Debug.WriteLine("Letto: " + barcode);
                                            //add  list to barcodes
                                            lstSelo.Add(barcode)
                       //send this list to my activity for refresh listview
                    }
    

    This is my activity:

     base.OnCreate(savedInstanceState);
    
            SetContentView(Resource.Layout.Cliente);
    
            ListView lstViewSelos = FindViewById<ListView>(Resource.Id.lstViewSelos);
    
    
            SelosAdapter seloAdapter = new SelosAdapter(this, //take list from thread but how??);
            lstViewSelos.Adapter = seloAdapter;
    
        //maybe this for refresh? but how ?
        seloAdapter.NotifyDataSetChanged();
    

    And my axml:

    <ListView
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/lstViewSelos" />
    

    Thanks

    Monday, May 22, 2017 2:53 PM

Answers

  • User258468 posted

    RunOnUiThread(()=> NotifyDataSetChanged());

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, May 22, 2017 6:54 PM

All replies

  • User325526 posted

    I found a way to retrieve my list from thread but i don't know how to refresh my listview or activity, i guess need be inside thread?

    Monday, May 22, 2017 3:24 PM
  • User258468 posted

    RunOnUiThread(()=> NotifyDataSetChanged());

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, May 22, 2017 6:54 PM
  • User325526 posted

    Thank you

    Wednesday, May 24, 2017 5:37 PM