title: Android fragment, function called in onViewCreated: setText aspect won't fly, cursor and rawQuery will...why's that?
body: <p>I'm working on an application that takes the rowid of a user selected record in a Sqlite database (shown using TableLayout), and displays the associated record on another fragment (DataEdit) for editing. This works GREAT only on the first time I open DataEdit after selecting a table row. However, if I go back to the table tab and select a different record, then go back to DataEdit tab, the selected row is not shown. Most curiously "selectedTableRecordView(v)" does run, even showing the desired rowid via a Toast message (see below code). Mapping this function to a button on the DataEdit tab and then pressing it after this second iteration causes the correct record to populate fields on this tab. What's up with this? I've tried cursor.close(), as well as database.close() with no relief. Any thoughts on what the matter could be? TIA</p>
  
  <pre><code>public class DataEdit extends Fragment implements OnClickListener {
  SQLiteDatabase d, db; 
  Cursor queryAll;  
  EditText edRowid, edSpecies, edArea, edSampler, edCount;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {     
      //String szSelectedRow=DataTable.szSelectedRow;     
      View v = inflater.inflate(R.layout.dataedit, container, false);
       return v;          
  }
  public void onViewCreated(View v, Bundle savedInstanceState) {
      super.onViewCreated(v, savedInstanceState);
  
      DBAdapter msdb= new DBAdapter(getActivity().getApplicationContext(),"adfg", null);     
      db=msdb.getWritableDatabase(); 
  
      //Button listeners on this fragment
      Button btnSaveRecord = (Button)v.findViewById(R.id.btnSaveRecordxml);
      btnSaveRecord.setOnClickListener(this);
      Button btnUpdateRecord = (Button)v.findViewById(R.id.btnUpdateRecordxml);
      btnUpdateRecord.setOnClickListener(this);
      Button btnDeleteRecord = (Button)v.findViewById(R.id.btnDeleteRecordxml);
      btnDeleteRecord.setOnClickListener(this);   
      Button btnResetForm = (Button)v.findViewById(R.id.btnResetFormxml);
      btnResetForm.setOnClickListener(this);
      Button btnFirstRecord = (Button)v.findViewById(R.id.btnFirstRecordxml);
      btnFirstRecord.setOnClickListener(this);
      Button btnPreviousRecord = (Button)v.findViewById(R.id.btnPreviousRecordxml);
      btnPreviousRecord.setOnClickListener(this);
      Button btnNextRecord = (Button)v.findViewById(R.id.btnNextRecordxml);
      btnNextRecord.setOnClickListener(this);
      Button btnLastRecord = (Button)v.findViewById(R.id.btnLastRecordxml);
      btnLastRecord.setOnClickListener(this);
  
  
      edRowid=(EditText)v.findViewById(R.id.edRowidxml);
      edSpecies=(EditText)v.findViewById(R.id.edSpeciesxml);
      edArea=(EditText)v.findViewById(R.id.edAreaxml);
      edSampler=(EditText)v.findViewById(R.id.edSamplerxml);
      edCount=(EditText)v.findViewById(R.id.edCountxml);
  
      selectedTableRecord(v);
  }
  </code></pre>
  
  <p>with selectedTableRecord(v) being,</p>
  
  <pre><code> public void selectedTableRecord(View v){
      Cursor c = db.rawQuery("SELECT * FROM surveyDB WHERE _id ="+DataTable.szSelectedRow,null);
          c.moveToFirst();            
          edRowid.setText(c.getString(0));
          edSpecies.setText(c.getString(1));
          edArea.setText(c.getString(2)); 
          edSampler.setText(c.getString(3));
          edCount.setText(c.getString(4));
          Toast.makeText(getActivity().getApplicationContext(), "Target rowid from within selectedTableRecord is"+DataTable.szSelectedRow+".", Toast.LENGTH_LONG).show(); 
  }
  </code></pre>