how to get listview position arralist value when i click on label in listview and get postion data

aamirmirza2899aamirmirza2899 Member ✭✭
edited January 14 in Xamarin.Forms
        <ListView
            SelectionMode="None"
            SeparatorColor="#f8f8f8"
            x:Name="flightlist"

            Margin="2"
            BackgroundColor="#f8f8f8"
            HasUnevenRows="true"
            RowHeight="300">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout
                            Margin="10"
                            Orientation="Vertical"
                            HorizontalOptions="FillAndExpand">

                           <Label text={ Binding name}?> 
                    <Buton text="buy book " x:name="btn" click="btn clicked" > 

                           </StackLayout>

Answers

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @aamirmirza2899 The ListView's flightlist.SelectedIndex will give the position in the array that you set to flightlist.ItemsSource.

  • aamirmirza2899aamirmirza2899 Member ✭✭

    @ShantimohanElchuri but i dont want whole item selected or item click , all i want is that when i click button view in listview i will get the arryalist position data for exam i an array list 0 to 10 value and every position i have name ,email,password,id,text that bind to tha list view ,and finallly when i tapped on name label how i got the postion of tabbed no item click because in listview item click means hole view l click

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @aamirmirza2899 Do you have multiple Labels in the same ViewCell whose Text property is set from an array of strings? Or od you have them on 10 separate items in the ListView?

    These two modes have to be dealt differently. What I said was for the later mode. You don't have to respond to Item clicked event. When you tap on any element in an item SelectedIndex will be set. But if you are having the first mode then it has to be dealt differently as grouping of several Views is not supported in Xamarin.Forms like in earlier versions of VS.

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @ShantimohanElchuri said:
    @aamirmirza2899 Do you have multiple Labels in the same ViewCell whose Text property is set from an array of strings? Or od you have them on 10 separate items in the ListView?

    These two modes have to be dealt differently. What I said was for the later mode. You don't have to respond to Item clicked event. When you tap on any element in an item SelectedIndex will be set. But if you are having the first mode then it has to be dealt differently as grouping of several Views is not supported in Xamarin.Forms like in earlier versions of VS.

    Sorry, there is no SelectedIndex in XF's ListView. Read it as SelectedItem.

  • aamirmirza2899aamirmirza2899 Member ✭✭
    edited January 16

    @ShantimohanElchuri
    hi shantimohan i hava listview in side view cell i have an lable when i tapped on label that tapped effect show on whole item tapped still i already give the selection mode none but still tapped on item not on label


    <ListView.ItemTemplate>



                                         </Label.GestureRecognizers>
                                            </StackLayout>
                                            <StackLayout IsVisible="false" Orientation="Vertical" HorizontalOptions="EndAndExpand">
                                                <Label Text="FREQUENT FLYER NO." TextColor="Gray" FontSize="Micro" />
                                                <Frame BackgroundColor="White" BorderColor="Gray" HasShadow="false" Padding="0" CornerRadius="0">
                                                    <Label BackgroundColor="Transparent" FontSize="Micro" Margin="5" TextColor="Black" />
                                                </Frame>
                                            </StackLayout>
                                        </StackLayout>
                                    </StackLayout>
                                </ViewCell>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>
    
  • LeoZhuLeoZhu Member ✭✭✭

    you could reference this : https://forums.xamarin.com/discussion/73470/detecting-tap-on-label-inside-viewcell-inside-listview

    Define the position attribute to the yourItem data model,with position you could get the data you want

Sign In or Register to comment.