How to pass multiple values from one activity to another activity?

Hi Experts,

I am using list view and on selected item from list view value should pass another activity because based on the value I am going to filter records in next activity.

I used below code to pass values on clicking item from list view

private void Jlist_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
string jrnlTemplate = InvJourList[e.Position].ToString();
Intent intent = new Intent(this, typeof(PhysicalInvJourActivity));
intent.PutExtra("Journals", jrnlTemplate);
StartActivity(intent);

    }

But here my complexity is from my first activity I need to send two values to next activity but in list view need to appear only one values, means ITEM001...PAR01 these two values I need to pass next activity but in first activity listview ITEM001 only need to appear.

Please give me a solution

Tagged:

Best Answer

«1

Answers

  • jezhjezh Member, Xamarin Team Xamurai
    edited April 15

    @sreedhar_msdax
    It is just the same. You can pass another value like the first one.
    For example:

     intent.PutExtra("yourkey", "test");  
    

    and

     string name = Intent.GetStringExtra("yourkey");
    

    Note: It doesn't matter which value you display.
    By the way, does the two values in the same object model ? Or , the two fields are in different data structures ?
    If the two values are in the same object model, you can also pass them as an object model.

  • sreedhar_msdaxsreedhar_msdax Member ✭✭✭

    Hi Jezh,

    Thanks for the suggestion,
    Both values are from different tables not from same DS.
    But based on your explanation is it not necessary to show the value in list view...??

  • jezhjezh Member, Xamarin Team Xamurai

    I don't mean that, I mean you can show it or not show it depending on your needs.

    Since the both values are from different tables , on what basis do you decide which two parameter values to pass?

  • sreedhar_msdaxsreedhar_msdax Member ✭✭✭

    Hi Jezh,

    You are correct that was my issue also I didn't able to flow this logically

  • sreedhar_msdaxsreedhar_msdax Member ✭✭✭

    If I have the values in same tables is it possible ??

  • jezhjezh Member, Xamarin Team Xamurai
    edited April 15

    If you could relate the selected item and the other value from different table, it will also work.

    Of course, it will be more convenient that you have the values in same tables .

  • sreedhar_msdaxsreedhar_msdax Member ✭✭✭

    Jezh, If you don't mind can I share my screen in skype if possible for you

  • jezhjezh Member, Xamarin Team Xamurai

    I am so sorry, we are forum supporters , this behavior is not supported by our company.
    You can explain your problem in details or image,we will answer your questions in time.

  • sreedhar_msdaxsreedhar_msdax Member ✭✭✭

    Ohh Okay thank you will share an image here

  • sreedhar_msdaxsreedhar_msdax Member ✭✭✭

    Hi Jezh,

    Here is my simulator screens I have given some explanation also. Please check

  • jezhjezh Member, Xamarin Team Xamurai

    Ok, and what I want to know is when you select a journaltemplate name option, what is the corresponding journalBatch name?

  • sreedhar_msdaxsreedhar_msdax Member ✭✭✭

    Hi Jezh,
    Sorry here Journal Template is PHYS.INV and Batch is JRNL-6...

    from first activity only need to pass both to next activity..

  • sreedhar_msdaxsreedhar_msdax Member ✭✭✭

    Below is my service xml

    Two activities having same web service and same data just we are filtering here based on previous activities

  • jezhjezh Member, Xamarin Team Xamurai
    edited April 16

    I'm getting a little confused.
    Regardless of which item you select in the listview, are these two values the same for the current page(Journal Template is PHYS.INV and Batch is JRNL-6)?

  • sreedhar_msdaxsreedhar_msdax Member ✭✭✭

    In first activity based on warehouse location selection Journal batches will get filtered --- this is from one web service and journal batch name and journal template will be available in this service

    Second activity is another web service but having template and batch name fields to filter items and third activity uses same web service as second because its an item detail

    Here I am passing only JRNL-6 from first activity based on that item list appeared in second activity, but requirement is to show item detail on clicking an item from second activity for that require Template name (PHYS.INV.) and Line number also

    So, Here what I required is in from first activity when I select Batch name (JRNL-6) it also need to pass along with template (PHYS.INV.) so that I can filter based on these I will forward you my third activity code you can get to know as of now I have manually inserted values in filter..

    string invJourDetail = Intent.GetStringExtra("InventJournal");
    string[] invDetail = invJourDetail.Split("");

    NavSOAPService4.PhyInvJournal physInvJourDetailBuffer = new PhyInvJournal();
    NavSOAPService4.PhyInvJournal_Service physInvJourDetail = new PhyInvJournal_Service
    {
    Credentials = new NetworkCredential("administrator", "itreenav")
    };
    NavSOAPService4.PhyInvJournal_Filter[] physInvJourDetail_Filter = { new PhyInvJournal_Filter() };

         physInvJourDetail_Filter[0].Field = PhyInvJournal_Fields.ItemDescription;
    
            physInvJourDetail_Filter[0].Criteria = invDetail[0];  // Item Bicycle is filtering here from second activity
    
            physInvJourDetailBuffer = physInvJourDetail.Read("PHYS. INV.", "JRNL-6", 10027);   //Filtering manually
    
    
                SerialNumber.Text   = physInvJourDetailBuffer.Item_No;
                //PartNumber.Text     = invJournalDetail.
                UnitOfMeasure.Text  = physInvJourDetailBuffer.Unit_of_Measure_Code;
                Quantity.Text       = "";
                ItemName.Text       = physInvJourDetailBuffer.ItemDescription;
    
  • sreedhar_msdaxsreedhar_msdax Member ✭✭✭

    Hi Jezh,

    physInvJourDetailBuffer = physInvJourDetail.Read("PHYS. INV.", "JRNL-6", 10027); //Filtering manually

    In this line it should be first activity selected values line number from second activity

  • jezhjezh Member, Xamarin Team Xamurai
    edited April 16

    Well, In this case ,I suggest you define an Object Model in first activity which contains two fields(journal batch name and journal template name ), for example

     public class JournalModel
    {
        public string mBatchName {  get; set; }
        public string mTemplateName { get; set; }
    }
    

    and define InvJourList like this:

      List<JournalModel> InvJourList = new List<JournalModel>();
    

    When you select the Listview In the first activity, you will get the whole Object Model which contains the two fileds(mBatchName 、mTemplateName ).

       protected void OnListItemClick(object sender, Android.Widget.AdapterView.ItemClickEventArgs e)
        {
            var listView = sender as ListView;
            var t = InvJourList[e.Position];
            Android.Widget.Toast.MakeText(this, t.mBatchName +"<---->" +t.mTemplateName  , 
            Android.Widget.ToastLength.Short).Show();
    
          // pass the two values
           Intent intent = new Intent(this, typeof(PhysicalInvJourActivity));
          intent.PutExtra("BatchName ", t.mBatchName);
          intent.PutExtra("TemplateName ", t.mTemplateName );
          StartActivity(intent);
        }
    
  • sreedhar_msdaxsreedhar_msdax Member ✭✭✭

    Hi Jezh,

    Thanks for reply.
    If I want to show only JRNL-6 in listview and want to hide PHYS.INV. but on selecting list view item it should pass..How can achieve this?

  • jezhjezh Member, Xamarin Team Xamurai

    You can define a class ( e.g. JournalAdapter ) which extends BaseAdapter.
    In this class (JournalAdapter), you can show fields you want others to see, and vice versa, you can hide fields you don't want to show.
    Besides, you can also custom the layout of row item .
    And inflate the layout like this:

     //for example,  the layout CustomView is  the layout of row item we create. 
      if (view == null) // no view to re-use, create new
            view = context.LayoutInflater.Inflate(Resource.Layout.CustomView, null);   
    

    There is a sample you can check : https://developer.xamarin.com/samples/monodroid/CustomRowView/

    Note: please notice this class HomeScreenAdapter.cs in the above sample .

    And the following document should be helpful for you.
    https://docs.microsoft.com/en-us/xamarin/android/user-interface/layouts/list-view/

  • sreedhar_msdaxsreedhar_msdax Member ✭✭✭

    HI Jezh,

    I think these will works with Xamarin Forms because unable to find "LayoutInflater"

  • jezhjezh Member, Xamarin Team Xamurai
    edited April 16

    The sample in the link I post is based on Xamarin Android. And I have tested the sample ,it works properly.

    I guess you have ignored the variable Activity context;' before the LayoutInflater`

     view = context.LayoutInflater.Inflate(Resource.Layout.CustomView, null);
    

    Besides, you can also use the following code instead:

    LayoutInflater inflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService);
    View view = inflater.Inflate(Resource.Layout.CustomView, null);
    
  • sreedhar_msdaxsreedhar_msdax Member ✭✭✭

    Yeah Jezh,
    Thanks.. will try this once and let you know if any difficulty...

  • jezhjezh Member, Xamarin Team Xamurai

    @sreedhar_msdax
    Have you resolved your problem?

  • sreedhar_msdaxsreedhar_msdax Member ✭✭✭

    HI Jezh,

    If a string is like below

    JRNL-6__PHYS. INV.__10027__Bicycle

    this is coming from first and second activity

    string invJourDetail = Intent.GetStringExtra("InventJournal"); //the above string is coming here
    string[] invDetail = invJourDetail.Split("_");

    I want to split this according to '_' (underscore) and need to store 4 values in different variables and I need item details based on below code

    I tried a code below to split and store in different variables its working in console app but not in xamarin, sample code is:

    string a = invDetail[0];
    string b = invDetail[2];
    string c = invDetail[4];
    string d = invDetail[6];

    This array pattern.

    NavSOAPService4.PhyInvJournal physInvJourDetailBuffer = new PhyInvJournal();
    NavSOAPService4.PhyInvJournal_Service physInvJourDetail = new PhyInvJournal_Service
    {
    Credentials = new NetworkCredential("administrator", "itreenav")
    };

    //Here those variables which are spitted I need to pass

        physInvJourDetailBuffer = physInvJourDetail.Read("PHYS. INV.", "JRNL-6", 10027);   
    
    
            SerialNumber.Text   = physInvJourDetailBuffer.Item_No;
            //PartNumber.Text     = invJournalDetail.
            UnitOfMeasure.Text  = physInvJourDetailBuffer.Unit_of_Measure_Code;
            Quantity.Text       = "";
            ItemName.Text       = physInvJourDetailBuffer.ItemDescription;
    

    Please suggest :smile:

  • sreedhar_msdaxsreedhar_msdax Member ✭✭✭

    Hi Jezh,
    Thanks I have done this its working ... :smile: and I can able to retrieve now the item details and now I need one more suggestion...

  • sreedhar_msdaxsreedhar_msdax Member ✭✭✭

    HI Jezh,

    I want to scan item and store the values in service how can I achieve this Xamarin Android

    I have gone through some links which are related to Xamarin Form usinf ZXing scanner will it for Xamarin Android..??

    Please suggest... :smile:

  • jezhjezh Member, Xamarin Team Xamurai

    @sreedhar_msdax
    Do you want to scan Qr code into string in xamarin android?

  • sreedhar_msdaxsreedhar_msdax Member ✭✭✭

    Yeah either QR or Barcode scanning I need to do.

  • jezhjezh Member, Xamarin Team Xamurai

    The ZXing.Net.Mobile include a sample for xamarin android, you can check it first.
    https://github.com/Redth/ZXing.Net.Mobile/tree/master/Samples/Android

  • sreedhar_msdaxsreedhar_msdax Member ✭✭✭

    Thanks Jezh,
    Okay will check it and let you know

  • sreedhar_msdaxsreedhar_msdax Member ✭✭✭

    Hi Jezh,
    While trying to install Zxing.Net.Mobile package into my project I am getting the below error..

    Severity Code Description Project File Line Suppression State
    Error NU1107 Version conflict detected for Xamarin.Android.Support.Compat. Install/reference Xamarin.Android.Support.Compat 27.0.2.1 directly to project SQLite to resolve this issue.
    SQLite -> Xamarin.Android.Support.Design 27.0.2.1 -> Xamarin.Android.Support.Compat (= 27.0.2.1)
    SQLite -> ZXing.Net.Mobile 2.4.1 -> Xamarin.Android.Support.v4 25.4.0.1 -> Xamarin.Android.Support.Compat (= 25.4.0.1). SQLite C:\Users\ITREE\source\repos\SQLite\SQLite\SQLite.csproj 1

  • jezhjezh Member, Xamarin Team Xamurai

    Well, I found the same error, and I resolved this problem by the following steps:
    1. uninstall Xamarin.Android.Support.Design 27.0.2.1 and install Xamarin.Android.Support.Design 25.4.0.1
    2. then install ZXing.Net.Mobile 2.4.1

  • sreedhar_msdaxsreedhar_msdax Member ✭✭✭

    Hi Jezh,

    I tried mentioned steps...but still getting same error

    Severity Code Description Project File Line Suppression State
    Error NU1107 Version conflict detected for Xamarin.Android.Support.Core.UI. Install/reference Xamarin.Android.Support.Core.UI 28.0.0.1 directly to project SQLite to resolve this issue.
    SQLite -> Xamarin.Android.Support.Design 28.0.0.1 -> Xamarin.Android.Support.Core.UI (= 28.0.0.1)
    SQLite -> ZXing.Net.Mobile 2.4.1 -> Xamarin.Android.Support.v4 25.4.0.1 -> Xamarin.Android.Support.Core.UI (= 25.4.0.1). SQLite C:\Users\ITREE\source\repos\SQLite\SQLite\SQLite.csproj 1

  • jezhjezh Member, Xamarin Team Xamurai
    edited April 24

    Hi @sreedhar_msdax
    What Nuget have you installed and what version are they?

  • sreedhar_msdaxsreedhar_msdax Member ✭✭✭

    What you have mentioned I uninstalled that and installed Xamarin.Android.Support.Design 25.4.0.1

    After that ZXing same version I installed then I got error

  • jezhjezh Member, Xamarin Team Xamurai

    Could you switch to the Installed tab ?

  • sreedhar_msdaxsreedhar_msdax Member ✭✭✭

    Hi here is my installed tab

  • jezhjezh Member, Xamarin Team Xamurai

    I have reproduced your problem, and you can try the following steps to resolve this question.
    1. uninstall Xamarin.Android.Support.Compat 28.0.0.1 and install Xamarin.Android.Support.Compat 25.4.0.1
    2. uninstall Xamarin.Android.Support.Design 28.0.0.1 and install Xamarin.Android.Support.Design 25.4.0.1
    3. then install ZXing.Net.Mobile 2.4.1

  • sreedhar_msdaxsreedhar_msdax Member ✭✭✭

    Hi Jezh,

    It got installed successfully. Thanks so using this assembly can I build bar code scanning activities and can store scanned item into my database right?

Sign In or Register to comment.