开发者

Android public void search(View view)

I am using the code found here.

The summary is that there is an xml file with an EditText and a Button called search. When search is clicked it is meant to search an SQLite db. I have added Log tracking to the oncreate and search methods but only the oncreate is running. This leads me to think that the search method is not executing when the button is开发者_运维知识库 clicked.

I know that the easy work around is to set and onclick listener. I am just wondering if the way the code is written at the moment is missing something or old and depreciated?

public void search(View view) {
    Log.v("SEARCH", "Was run    ");
    // || is the concatenation operation in SQLite
            cursor = db.rawQuery("SELECT * FROM employee" , null);
            adapter = new SimpleCursorAdapter(
                            this, 
                            R.layout.employee_list_item, 
                            cursor, 
                            new String[] {"firstName", "lastName", "title"}, 
                            new int[] {R.id.firstName, R.id.lastName, R.id.title});
            employeeList.setAdapter(adapter);
}

Any help is appreciated.

Max


did you register your search method to run? Could you show your xml?

You should have in your xml something like this:

<button android:layout_width="fill_parent" android:layout_height="wrap_content" android:onClick="search"/>

If you don't use the onClick property then your button won't know which method to call when it's tapped.


Did you specify onClick handler in your XML?

For example please see http://android-developers.blogspot.com/2009/10/ui-framework-changes-in-android-16.html) and look for "Easier click listeners"

in your case button should have android:onClick="search" attribute in layout.xml


You need to either call setOnClickListener for the button in your activity's onCreate method, or else name an activity method using an attribute android:onClick="search" for the button in the XML.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜