AutoCompleteTextView OnItemClickListener如何从数据库中返回确切的选定项?

时间:2014-01-13 08:46:46

标签: java autocompletetextview onitemclicklistener

我有这个方法从数据库和ArrayAdapter获取数据字符串,以便在我的活动中获取这些数据。我正在尝试使用item的id获取每个项目的setOnItemClickListener以获取特定值。但我的应用程序崩溃onItemClick。你能帮我解决这个问题吗?提前谢谢。

这是获取数据字符串的方法;

 public String[] storedTrainees() {
    Cursor cursor = db.query(TABLE_PERSON, new String[] { PERSON_ID,
            PERSON_FIRSTNAME, PERSON_LASTNAME, PERSON_EMAIL }, null, null,
            null, null, null);

    String[] trainee = new String[cursor.getCount()];
    int id = cursor.getColumnIndex(PERSON_ID);

    while (cursor.moveToNext()) {
        trainee[id] = cursor.getString(cursor
                .getColumnIndex(PERSON_FIRSTNAME))
                + " "
                + cursor.getString(cursor.getColumnIndex(PERSON_LASTNAME))
                + "\n"
                + cursor.getString(cursor.getColumnIndex(PERSON_EMAIL));
        id++;
    }
    return trainee;

}

这是我的活动课程。

        SearchTrainee = (AutoCompleteTextView) findViewById(R.id.search);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            R.layout.search_autocomplete, DatabaseHelper.getInstance()
                    .storedTrainees());
    SearchTrainee.setAdapter(adapter);

    SearchTrainee.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {

            // Log.i("DEBUG", currentTrainee.getFirstname());
            /*
             * SharedMemory.getInstance().setCurrentTrainee(currentTrainee);
             * Log.i("DEBUG", currentTrainee.getFirstname());
             * Toast.makeText( getApplicationContext(), "CLIK !",
             * Toast.LENGTH_LONG ).show();
             */
        }

    });

0 个答案:

没有答案