This code basically fetches data from database and display it in a list along with a searchbox which helps in filtering out specific values from list.
Please check this snapshot!

But the problem is DataAttach.java is extended from Activity which doesn’t support onListItemClick().
If I want to include onListItemClick(),
I must extend the class from ListActivity instead of Activity.
Here comes the problem.
If I extend the class from ListActivity, I can’t include the searchbox in my view.
I’m stuck into deadlock, any suggestions appreciated. Thanks.
DataAttach.java(snippet):
symbolarr = dbM.getSymbol();
if (symbolarr != null) {
list1 = new String[symbolarr.length];
for (int i = 0; i < symbolarr.length; i++) {
list1[i] = symbolarr[i];
}
}
// ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
// android.R.layout.simple_list_item_1, symbolarr);
// setListAdapter(adapter);
lv.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, symbolarr));
DbManager.java(snippet)
public String[] getSymbol() {
Cursor cur;
try {
cur = mDb.rawQuery("select symbol,company_name from scrip", null);
} catch (SQLiteException e) {
throw new Error(" *** ERROR in cursor *** " + e.getMessage());
}
String[] b1 = new String[1326];
int x = 0;
if (cur.moveToFirst()) {
do {
b1[x] = cur.getString(cur.getColumnIndex("symbol"));
x++;
} while (cur.moveToNext());
}
cur.close();
return b1;
}
main.xml
< LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="@+id/MainLayout">
< EditText android:id="@+id/txt1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:hint="Search">
< /EditText>
< ListView android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
< /ListView>
< /LinearLayout>
You can actually go either way:
Define a ListActivity with custom layout: http://developer.android.com/reference/android/app/ListActivity.html Note that you MUST set id like this
@android:id/list.Without
ListActivity: usesetOnItemClickListener(AdapterView.OnItemClickListener listener)on yourListView.