title: How to get information from a customized ListView in Android
body: <p>I have a ListView that I have customized to display information gathered from an SQLite database.  Each item is a represented using a CardView widget containing TextViews.  I have set the ListView property in the .xml file to:</p>
  
  <p><code>android:choiceMode="singleChoice"</code></p>
  
  <p>allowing the user to make a selection from the list.</p>
  
  <p>When the user clicks the floating action button, I want to be able to take information displayed in one of the TextViews of the CardView selected in the ListView.</p>
  
  <p>I have looked at other questions on the topic and they suggest using the onClick method, but I do not understand how that would work because I do not want to retrieve the information when the user makes the selection from the list.  Rather, I want the information when they have selected the floating action button.</p>
  
  <p>Here is part of my Activity code:</p>
  
  <pre><code>public class SetViewerActivity extends AppCompatActivity {
  
  private static final String TAG = "SetViewerActivity";
  private boolean fabState;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      // set contents of activity
      setContentView(R.layout.activity_set_viewer);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
  
      // set action for main floating action button
      FloatingActionButton fab = (FloatingActionButton) 
   findViewById(R.id.fab);
      fabState = false;
      fab.setOnClickListener(new View.OnClickListener() {
          // get set info and edit in new Activity
          @Override
          public void onClick(View view) {
              editSelectedSet(view);
          }
      });
  
      // set up list view and populate with custom set info from database
      SQLiteDatabase db = new MemCardSQLiteHelper(this).getReadableDatabase();
      Cursor cursor = db.rawQuery(MemCardDbContract.Sets.SELECT_ALL_SETS, 
  null);
      ListView lvSets = (ListView) findViewById(R.id.listViewSets);
      SetViewAdapter adapter = new SetViewAdapter(this, cursor);
      lvSets.setAdapter(adapter);
  }
  
  private void editSelectedSet(View view) {
  
      // HOW DO I FIND THE SET INFORMATION HERE ??        
  
      // start activity with selected set information for editing
      Intent intent = new Intent(this, CreateNewSet.class);
      intent.putExtra(MainActivity.CREATE_SET_NUM, selectedSet);
      startActivity(intent);
  }
  }
  </code></pre>
  
  <p>and here is my xml for each ListView item:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:padding="10dp"&gt;
  &lt;android.support.v7.widget.CardView
      android:layout_width="wrap_content"
      android:layout_height="match_parent"
      app:cardCornerRadius="4dp"
      app:cardElevation="2dp"
      app:contentPadding="2dp"&gt;
      &lt;android.support.constraint.ConstraintLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
          &lt;TextView
              android:id="@+id/textViewName"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="8dp"
              android:layout_marginRight="8dp"
              android:layout_marginTop="8dp"
              android:layout_weight="1"
              app:layout_constraintLeft_toLeftOf="parent"
              app:layout_constraintRight_toRightOf="parent"
              app:layout_constraintTop_toTopOf="parent" /&gt;
          &lt;TextView
              android:id="@+id/textViewAmount"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="8dp"
              android:layout_marginRight="8dp"
              android:layout_marginTop="8dp"
              android:layout_weight="1"
              app:layout_constraintHorizontal_bias="0.0"
              app:layout_constraintLeft_toLeftOf="parent"
              app:layout_constraintRight_toRightOf="parent"
              app:layout_constraintTop_toBottomOf="@+id/textViewName" /&gt;
          &lt;TextView
              android:id="@+id/textViewColour"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="8dp"
              android:layout_marginRight="8dp"
              android:layout_marginTop="10dp"
              android:layout_weight="1"
              app:layout_constraintLeft_toLeftOf="parent"
              app:layout_constraintRight_toRightOf="parent"
              app:layout_constraintHorizontal_bias="0.0"
              app:layout_constraintTop_toBottomOf="@+id/textViewAmount" /&gt;
          &lt;TextView
              android:id="@+id/textViewSetId"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:visibility="gone" /&gt;
      &lt;/android.support.constraint.ConstraintLayout&gt;
  &lt;/android.support.v7.widget.CardView&gt;
  &lt;/LinearLayout&gt;
  </code></pre>