如何设置setOnClickListener为AutoCompleteTextView? [英] how to set setOnClickListener for AutoCompleteTextView?

查看:190
本文介绍了如何设置setOnClickListener为AutoCompleteTextView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的AutoCompleteTextView.After选择文本,我想申请setonclicklistener到text.if任何选择都有想法。

I am selecting text for AutoCompleteTextView.After i want apply setonclicklistener to selected text.if any have idea.

ArrayAdapter<String> arrAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, sampleACTV); 
 AutoCompleteTextView ACTV = (AutoCompleteTextView) findViewById(R.id.spinner);
 ACTV.setAdapter(arrAdapter); 

 }
 private static final String[] sampleACTV = new String[]
         { "android","androidpeople.com","iphone","blackberry" }; 

在我的例子中,我选择一个像机器人打电话的意图去鸟巢活性的研究

in my example i am selecting one like android call an intent to go to nest Acitivity

推荐答案

有不同的点击听众AutoCompleteTextView。

There are different click listeners in AutoCompleteTextView.

第一种方法是在布局XML中,可以定义onclick属性,与要调用的函数,在下面的例子中,点击。

The first way is in the layout xml, you can define the onCLick attribute, with the function that you want to be called, in the example below, clicked.

<AutoCompleteTextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/spinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:onClick="clicked" />

然后,在你的活动,你定义函数点击。

Then, in your activity, you define the function clicked.

public void clicked(View v) { 
  // on click do ..
} 

或者你也可以在你的code直接设置它:

Or you can set it directly in your code:

ACTV.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        finish();
    }
});

如果您希望当用户点击在下拉列表中的项目还有另一种方法,设置点击监听器的 setOnItemClickListener 的。

If you want to set the click listener when the user clicks in an item in the dropdown list there is another method, the setOnItemClickListener.

ACTV.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
        //... your stuff
    }
})

和你有一个最后的选择,设置点击监听器,当用户实际使用选择下拉列表中的某个项目的 setOnItemSelectedListener 的。

And you have a last option, to set the click listener when the user actually selects an item in the dropdown list using setOnItemSelectedListener.

ACTV.setOnSelectedListener(new OnItemClickListener() {
    @Override
    public void onItemSelected (AdapterView<?> parent, View view, int position, long id) {
        //... your stuff
    }
})

参考文献:

<一个href="http://developer.android.com/reference/android/widget/AutoCompleteTextView.html">http://developer.android.com/reference/android/widget/AutoCompleteTextView.html

祝你好运!

这篇关于如何设置setOnClickListener为AutoCompleteTextView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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