Android 上的 AutoCompleteTextView 单击事件 [英] AutoCompleteTextView click event on Android

查看:53
本文介绍了Android 上的 AutoCompleteTextView 单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功地实现了我的 AutoCompleteTextView,它基于一个 SQLite 查询并被放置在一个阵列适配器.这一切都很好,但是我无法让我的 onclickevent 工作.

I have successfully implemented my AutoCompleteTextView which is based off an SQLite query and is placed in an array adapter. That's all working beautifully, however I can't get my onclickevent working.

我只想创建一个将选定值传递给新活动的意图.我知道如何创建一个 onclicklistener.我只是不确定如何将它应用到 AutoCompleteTextView 的下拉框中.

I just want to create an intent to pass the selected value to a new activity. I know how to create an onclicklistener. I am just unsure about how to apply it to the dropdown box of the AutoCompleteTextView.

推荐答案

没关系.我已经解决了.我只是表现不佳.下面的代码基于一个简单的 SELECT SQLite 语句自动完成我的文本视图,并在用户从下拉列表中选择大学时执行.

Nevermind. I've solved it. I was just executing poorly. The code below autocompletes my textview based off a simple SELECT SQLite statement and executes when the user selects the university from the dropdown list.

onclick 事件会创建一个新的 Intent 并启动一个新的 Activity,将选择传递给该 Intent 中的该 Activity.

The onclick event creates a new intent and starts a new activity passing the selection to this activity within the intent.

final AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.ac_university);
String[] universities = myDbHelper.getAllUnis(db);

// Print out the values to the log
for(int i = 0; i < universities.length; i++)
{
    Log.i(this.toString(), universities[i]);
}

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, universities);
textView.setAdapter(adapter);

//textView.setOnItemSelectedListener(this);
textView.setOnItemClickListener(new OnItemClickListener() {

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

        Intent intent = new Intent(Main.this, Campus.class);
        Bundle bundle = new Bundle();

        bundle.putString("university_name", arg0.getItemAtPosition(arg2).toString());
        bundle.putLong("_id", arg3);
        intent.putExtras(bundle);
        startActivity(intent);
    }

这篇关于Android 上的 AutoCompleteTextView 单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆