Sorunu şu şekilde çözdüm. Staff_ids ve staff_names'leri yerel SQLite veritabanından aldım, daha sonra aynı zamanda bir çalışanAlan Dizisi ArrayList ve çalışanIdArray bir ArrayList oluşturdum. Bu nedenle, workerIdArray [0], workerNameArray [0] ile eşleşir, employeeIdArray [1], employeeNameArray [1] ile eşleşir.
ArrayLists oluşturulduktan sonra, staffNameArray öğesini ListView'e ekledim.
Daha sonra ,ListItemClick'te, seçili ListView satırının konumunu geri alırım. Bu 'konum' ArrayLists'teki konuma göre koordine olacaktır - bu yüzden ListView'de ilk satırı seçersem, konum sıfır olur ve employeeNameArray [0], employeeIdArray [0] ile eşleşir. ÇalışanIdArray'dan coroloating girdisini alıyorum ve putExtra'yı kullanarak bir sonraki etkinliğe itiyorum.
public class MyFirstDatabase extends ListActivity {
ArrayList<String> employeeIdArray = new ArrayList<String>(); // List of EmployeeIDs
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Open the database
SQLiteDatabase db;
db = openOrCreateDatabase("mydb.db",SQLiteDatabase.CREATE_IF_NECESSARY, null);
db.setVersion(1);
db.setLocale(Locale.getDefault());
db.setLockingEnabled(true);
// Query the database
Cursor cur = db.query("employee", null, null, null, null, null, "employee_lastname");
cur.moveToFirst(); // move to the begin of the db results
ArrayList<String> employeeNameArray = new ArrayList<String>(); // Initialize mArrayList
while (cur.isAfterLast() == false) {
employeeNameArray.add(cur.getString(1)); // add the employee name to the nameArray
employeeIdArray.add(cur.getString(0)); // add the employee id to the idArray
cur.moveToNext(); // move to the next result set in the cursor
}
cur.close(); // close the cursor
// put the nameArray into the ListView
setListAdapter(new ArrayAdapter<String>(this,R.layout.list_item,employeeNameArray));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
}
protected void onListItemClick(ListView l, View v, final int position, long id) {
super.onListItemClick(l, v, position, id);
Intent myIntent = new Intent(this, SubView.class); // when a row is tapped, load SubView.class
Integer selectionID = Integer.parseInt(employeeIdArray.get(position)); // get the value from employeIdArray which corrosponds to the 'position' of the selected row
myIntent.putExtra("RowID", selectionID); // add selectionID to the Intent
startActivityForResult(myIntent, 0); // display SubView.class
}
}
Eğer bir filtreye izin verildiyse, filtreden sonra ilk sonuç her zaman 0 pozisyonunu üretecektir ... bu yüzden bunu yapmak doğru yol değildir – chhameed