Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

How to show more the one field in a ListView / other control…?

$
0
0

Hi all

I am an absolute newbie to Xamarin.Forms and need some help.
I have created an app, that queries our web-service and shows the result in a page with a listview.
My app is based on the template Blank App (Xamarin.Forms Shared).
The result of the query is stored in a List with objects of type “Empfehlung”.

The app is working:

  • I can show a (one) field (“cPAB_Firma” see code-sniped below) from the result-object as TextCell

  • I can capture the click-event from the ListView

  • In the click-Event, I can create an object that contains all (the in object Empfehlung) defined fields and show an alert with some of the fields

    Code-Snipped:

    // Some code to fill piServerAuswahl, etc.
    
    //..  
                   var es = await sv.GetEmpfehlungenAsync(cURL); // Call WebService
    
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
    
                    {
                        lStatusAbfrage.Text = es.Count + " Empfehlungen wurden geladen"; // Update label with count of received “Empfehlungen”
                        lvErgebnisAnzeige.ItemsSource = es; // es = List with objects from type „Empfehlung“ (0-n)
                    });
                };
    
                lvErgebnisAnzeige = new ListView();
                lvErgebnisAnzeige.ItemTemplate = new DataTemplate(typeof(TextCell));
                lvErgebnisAnzeige.ItemTemplate.SetBinding(TextCell.TextProperty, "cPAB_Firma");
                //
                lvErgebnisAnzeige.ItemSelected += (sender, e) =>
                {
                    var eq = (Empfehlung)e.SelectedItem;
                    string cAnzeige = "Selektiert: " + eq.cPAB_Firma.Trim() + ", " + eq.cPAB_Strasse.Trim() + ", " + eq.cPAB_PLZ.Trim() + " " + eq.cPAB_Ort.Trim() + " / Key: " + eq.iPFA_Key;
                    DisplayAlert("Empfehlung info", cAnzeige, "OK");
                };
    
                Content = new StackLayout
                {
                    Padding = new Thickness(0, 20, 0, 0),
                    Children = { 
                        lStatusAbfrage, 
                        bFoto,
                        piServerAuswahl,
                        piUmkreis,
                        btEmpfehlungenLaden, 
                        lvErgebnisAnzeige 
                    }
                };
            }
    

Now, I want to change the code to show all the fields from the query

Example:

Actual the app shows in the ListView:

cPAB_Firma [0]

---- End Entry 1 ------------

cPAB_Firma [1]

---- End Entry 2 ------------

cPAB_Firma [2]

---- End Entry 3 ------------

cPAB_Firma […]

---- End Entry n ------------

I want to change this to (Example):

cPAB_Firma [0]

cPAB_Strasse [0]

cPAB_PLZ [0] + „ „ + cPAB_Ort [0]

cPAB_...... [0]

---- End Entry 1 ------------

cPAB_Firma [1]

cPAB_Strasse [1]

cPAB_PLZ [1] + „ „ + cPAB_Ort [1]

cPAB_...... [1]

---- End Entry 2 ------------

cPAB_Firma [2]

cPAB_... [2]

---- End Entry 3 ------------

As showed in code, I should also be able to add some of the fields together (cPAB_PLZ [1] + „ „ + cPAB_Ort [1])
Further also some images are included in the query and I should be able to create the content dynamically:
Example:

if (cPAB_Firma [1] == “”)
{ // do / show nothing ; }
Else
{// show content }

If an entry is clicked, I then have to query the webservice with the key (which is also defined in the object “Empfehlung” -> field eq.iPFA_Key in the alert) and show the result on a detail-page, that I then also have to create dynamically (only show the fields that contains data), but that’s the next step :-) 

I think with ListView I am able to bind only one item?

How to solve this problem make it on another way?

As I am an absolute beginner, I would be very grateful for an example code with some of the fields (e.g. cPAB_Firma, cPAB_Strasse, cPAB_PLZ) so that I can find the entry.
**
**Any help is highly appreciated

**Thanks a lot
**


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>