0

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?

Community
  • 1
  • 1
Maximus
  • 471
  • 1
  • 10
  • 25
  • Can you clarify your question? Are you asking if it is possible to detect which "column" in your list item was long pressed, or simply how to access a specific field in the model object that you retrieved with `getItemAtPosition()`? – devunwired Nov 14 '12 at 19:02
  • Can you post what kind of adapter you are using, possibly all you need to do is change the tostring method – nandeesh Nov 14 '12 at 19:04
  • I want not array as at picture from parent.getItemAtPosition(position).toString(). I want something like parent.getItemAtPosition(position).getString("birthday"), which will return "Дата народження", or parent.getItemAtPosition(position).getString("first_name"), which will return "Імена" and etc. I need to get concretely TextView's value of concretely adapter's row, which binded on some listview. – Maximus Nov 14 '12 at 19:07
  • nandeesh, sure. WorkersListAdapter = new SimpleAdapter(this, WorkersArrayList, R.layout.listview_row, new String[] {"first_name", "last_name", "experience", "birthday", "job", "academic_degree", "academic_title", "operative_rank"}, new int[] {R.id.first_name, R.id.last_name, R.id.experience, R.id.birthday, R.id.job, R.id.academic_degree, R.id.academic_title, R.id.operative_rank}); list.setAdapter(WorkersListAdapter); – Maximus Nov 14 '12 at 19:08

2 Answers2

2

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

((Map)parent.getItemAtPosition(position)).get("birthday").toString()
nandeesh
  • 24,740
  • 6
  • 69
  • 79
0

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

Paul Fleming
  • 24,238
  • 8
  • 76
  • 113
Sheetal K
  • 1
  • 1