Note that there are some explanatory texts on larger screens.

plurals
  1. POhow can i know the id of an item in the listview when it has been filtered? Android
    primarykey
    data
    text
    <p>can you help me guys, cause i made a edittext on top of the listview for filtering data on time, but when it has been filtered, the first index is always been 0... thus i filter the 50th line, i failed to get its parent id</p> <pre><code>public class Moshimoshi extends Activity { /** Called when the activity is first created. */ private ListView lv; private EditText ed; ArrayAdapter&lt;String&gt; adapterForListview; ContentResolver cr; private long[] item_id; private String lv_arr[]; int textlength = 0; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); cr = getContentResolver(); lv = (ListView) findViewById(R.id.listView1); ed = (EditText) findViewById(R.id.editText1); adapterForListview = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1); viewData(); lv.setAdapter(new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, lv_arr)); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; a, View v, int position, long id) { Log.i(String.valueOf(id), String.valueOf(item_id[(int) id])); Intent info = new Intent(getApplicationContext(), Info.class); int rowid = (int) item_id[(int) id]; info.putExtra("key", rowid); // update.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); // startActivity(info); } }); ed.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { textlength = ed.getText().length(); adapterForListview.clear(); for (int i = 0; i &lt; lv_arr.length; i++) { if (textlength &lt;= lv_arr[i].length()) { if (ed.getText() .toString() .equalsIgnoreCase( (String) lv_arr[i].subSequence(0, textlength))) { adapterForListview.add(lv_arr[i]); } } } lv.setAdapter(adapterForListview); } }); } public void viewData() { // Cursor cursor = conRes.query(CONTENT_URI_Applicant, new String[] { // _ID, // FName, LName }, null, null, FName); Cursor cursor = cr.query(CONTENT_URI_rawquery, null, "Select _id,FName,LName FROM Applicant", null, null); startManagingCursor(cursor); while (cursor.moveToNext()) { // Could use getColumnIndexOrThrow() to get indexes adapterForListview.add(cursor.getString(cursor .getColumnIndex(FName)) + " " + cursor.getString(cursor.getColumnIndex(LName))); // i++; // Log.i("Id", String.valueOf(item_id[i])); } item_id = new long[cursor.getCount()]; lv_arr = new String[cursor.getCount()]; int i = 0; for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { item_id[i] = cursor.getLong(cursor.getColumnIndex(_ID)); lv_arr[i] = cursor.getString(cursor.getColumnIndex(FName)) + " " + cursor.getString(cursor.getColumnIndex(LName)); Log.v("ite_id:" + i, "" + item_id[i]); i++; } cursor.close(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload