Maximus
Maximus

Reputation: 471

ListView.onItemLongClick - get item's element

I created linearlayout with textviews which is ListView's row (because I need a table: Is any normal table view in Android?). It's layout sample of listview's row:

   <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:paddingTop="4dip"
     android:paddingBottom="6dip"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:orientation="horizontal">

     <TextView android:id="@+id/first_name"
         android:layout_width="100dip"
         android:layout_height="wrap_content" />

     <TextView android:id="@+id/last_name"
         android:layout_width="100dip"
         android:layout_height="wrap_content" />

     <TextView android:id="@+id/experience"
         android:layout_width="100dip"
         android:layout_height="wrap_content" />

     <TextView android:id="@+id/birthday"
         android:layout_width="100dip"
         android:layout_height="wrap_content">

</LinearLayout>

Now I need to get every field's value of selected row. I'm try

   ListView list = (ListView) findViewById(R.id.workers_list);
    list.setOnItemLongClickListener(new OnItemLongClickListener() {

            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                alert(parent.getItemAtPosition(position).toString()); // alert is Toast
                return true;
            }
        });

but it returns all data in interesting(?) data format: enter image description here how to get not all data of row, but only some column's value?

Upvotes: 0

Views: 5546

Answers (2)

Sheetal K
Sheetal K

Reputation: 1

If you want to use table, then you can use table layout

Upvotes: 0

nandeesh
nandeesh

Reputation: 24820

getItemAtPosition returns the Map at the position. So You could do

((Map)parent.getItemAtPosition(position)).get("birthday").toString()

Upvotes: 2

Related Questions