Q: setContentView doesn't allow search to work I have been tryng to get my search function working ever since adopting TabHosts and I have figured out that in my onCreate method for my Search class that when setContentView(R.layout.main); it causes the following error
03-30 09:19:53.301: E/AndroidRuntime(728): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@4053c270 is not valid; is your activity running?

When I comment it out though the search dialog pops up when you click on the hardware search button and I can type a value and press search but then I get the next stumbling block
03-30 09:23:37.061: D/PhoneWindow(776): couldn't save which view has focus because the focused view com.android.internal.policy.impl.PhoneWindow$DecorView@4053ff38 has no id.

Below is my code as it is at the moment for my Search class
public class Search extends ListActivity {

private TextView mTextView;
//protected ListAdapter adapter;
private DxDbAdapter mDbHelper;
DxSimpleCursorAdapter adapter;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.main);

    //mTextView = (TextView) findViewById(R.id.text1);

    // Get the intent, verify the action and get the query
    Intent intent = getIntent();
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
      String query = intent.getStringExtra(SearchManager.QUERY);
      doMySearch(query);
    }
}

public void doMySearch(String query_results) {
    //SQLiteDatabase db = (new DatabaseHelper(this)).getWritableDatabase();

    mDbHelper = new DxDbAdapter(this);
    mDbHelper.open();

    String[] columns = new String[] {"diagnosis", "diagcode"};
    int[] to = new int[] {R.id.diagnosis, R.id.code};

    //  Add "No Results Found" message 

    Cursor cursor = mDbHelper.search(query_results.trim());
    //Cursor cursor = db.rawQuery("Select _id, diagnosis, diagcode From DiagLookup Where diagnosis Like ? order by diagnosis asc", new String[]{"%"+query_results.trim()+"%"});

/*      if (cursor == null) {
        mTextView.setText(getString(R.string.no_results, new Object[] {query_results}));
    }
    else {*/ 
        adapter = new DxSimpleCursorAdapter(this,R.layout.list_detail,cursor,columns,to);
        setListAdapter(adapter);
 //     }
}

public void onListItemClick(ListView parent, View view, int position, long id) {
    SQLiteDatabase db = (new DatabaseHelper(this)).getWritableDatabase();
    Cursor c = (Cursor) getListAdapter().getItem(position);
    String arg = c.getString(c.getColumnIndex("_id"));
    Cursor cursor = db.rawQuery("Select category, subcategory From DiagLookup Where _id = ?",  new String[]{""+arg});
    cursor.moveToFirst();

    Context context = getApplicationContext();
    CharSequence text = "Category: " + cursor.getString(cursor.getColumnIndex("category")) + "\nSubcategory: " + cursor.getString(cursor.getColumnIndex("subcategory"));
    int duration = Toast.LENGTH_SHORT;

    Toast toast = Toast.makeText(context, text, duration);
    toast.show();
}
}

Furthermore I created a custom SimpleCursorAdapter so I can do some actions to an imageview. When I originally had entered adapter = new SimpleCursorAdapter(this,R.layout.list_detail,cursor,columns,to); entering a search term and pressing on the search button had populated the listview but my imageview was not functioning so when I just changed the code to adapter = new DxSimpleCursorAdapter(this,R.layout.list_detail,cursor,columns,to); and added on the top DxSimpleCursorAdapter adapter; it no longer worked and caused the couldn't save focus error.
I am using TabActivity and ActivityGroup to create tabs along the top of my app and I think my context is messed up which is causing the focus to be lost...I am not sure though.
Anyone with some guidance on how I can go about solving these issues?
Thanks in advance.

A: *

*If you are using TabActivity, why use the ListActivity again? If you want to use the ListView inside the Tabs, you can simply define it in the layout xml file.

*If you want to use the Tabs inside an activity, then try this out, Android: TabHost without TabActivity

*Switch to ViewPager instead of TabActivity Set default page for ViewPager in Android
