如何为 AutoCompleteTextView 设置 setOnClickListener?
我正在为 AutoCompleteTextView 选择文本。我想将 setonclicklistener 应用于所选文本后。如果有任何想法。
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" };
在我的示例中,我选择一个类似 android
的调用意图去嵌套 Acitivity
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
AutoCompleteTextView 中有不同的点击监听器。
第一种方式是在layout xml中,你可以定义onCLick属性,用你想要调用的函数,在下面的例子中,clicked。
然后,在您的活动中,您定义单击的功能。
或者您可以直接在代码中设置它:
如果您想在用户单击下拉列表中的项目时设置单击侦听器,则可以使用另一种方法,即 setOnItemClickListener。
您还有最后一个选项,当用户实际使用 setOnItemSelectedListener 在下拉列表中选择项目时设置点击侦听器。
参考文献:
http://developer.android.com/reference/android/widget/AutoCompleteTextView .html
祝你好运!
There are different click listeners in AutoCompleteTextView.
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.
Then, in your activity, you define the function clicked.
Or you can set it directly in your code:
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.
And you have a last option, to set the click listener when the user actually selects an item in the dropdown list using setOnItemSelectedListener.
References:
http://developer.android.com/reference/android/widget/AutoCompleteTextView.html
Good luck!
您需要创建自定义适配器并将 OnClick 事件分配给 getView() 中的视图
You need to create Custom Adapter and assign OnClick event to the view in getView()
创建一个自定义适配器,并在该 getView() 方法中放置 setonclicklistenerforeach 视图并调用接口方法。
覆盖片段中的接口并将其传递给适配器,以便 onclick 您将在片段中获得点击。
这将在每种情况下按照您的意愿工作。
如果您有任何建议,请告诉我,谢谢。
Create a custom adapter and in that getView() method put setonclicklistenerforeach view and call interface method.
Override interface in fragment and pass that to adapter so onclick you'll get click in fragment.
this will work as you wanted in every scenario.
Please if you have any suggestion do let me know thanks.
这是一篇非常旧的帖子,所以我不确定这会有多大帮助,但是......现在在 Kotlin 中这真的很容易。我有一个文本自动完成功能,其中填充了字典中的值,并且访问名为 searchAutoComplete 的自动完成功能的下拉文本是...
This is a really old post so I'm not sure how helpful this will be but... in Kotlin now this is really easy. I have a text auto-complete that is populated with with values from a dictionary and accessing the dropdown text for an auto-complete called searchAutoComplete is ...
这对我来说非常有效
This works perfectly for me