autocompletetextview 在弹出窗口中不起作用 [英] autocompletetextview not working inside popup window

查看:29
本文介绍了autocompletetextview 在弹出窗口中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 android 新手,我正在尝试将 auto complete text view 集成到弹出窗口中.但是自动完成操作在弹出窗口内不起作用.如果我将自动完成文本视图放在弹出式自动完成之外,则可以正常工作.

I am new to android and i am trying to integrate auto complete text view inside popup window. But the auto complete action not working inside the popup window. If i placed the auto complete text view outside the popup auto complete works fine.

弹窗的xml代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:layout_gravity="center_horizontal"
   android:orientation="vertical" >

   <LinearLayout
       android:id="@+id/popup"
       android:layout_width="300dp"
       android:layout_height="match_parent"
       android:layout_gravity="center_horizontal"
       android:gravity="center_horizontal"
       android:orientation="vertical"
       tools:ignore="UselessParent" >

       <FrameLayout
     android:id="@+id/innertop"
     android:layout_width="match_parent"
     android:layout_height="55dp"
        >


     <AutoCompleteTextView
         android:id="@+id/listitem"
         style="@style/CodeFont"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginBottom="4dp"
         android:background="@drawable/border"
         android:hint="@string/search_products_"
         android:textSize="12sp"
         android:typeface="serif" />

     <Button
         android:id="@+id/searchbtn1"
         android:layout_width="32dp"
         android:layout_height="32dp"
         android:layout_gravity="center_vertical|right"
         android:layout_marginRight="10dp"
         android:layout_marginBottom="1dp"
         android:background="@drawable/search_icon" />

 </FrameLayout>

   </LinearLayout>

</LinearLayout>

Activity java 代码:

final TextView btnOpenPopup1 = (TextView)findViewById(R.id.textView6);
                               btnOpenPopup1.setOnClickListener(new TextView.OnClickListener(){

                       @Override
                          public void onClick(View arg0) {
                           LayoutInflater layoutInflater
                            = (LayoutInflater)getBaseContext()
                             .getSystemService(LAYOUT_INFLATER_SERVICE);  
                           View popupView = layoutInflater.inflate(R.layout.login_popup, null);  
                                    final PopupWindow popupWindow = new PopupWindow(
                                      popupView,
                                      LayoutParams.WRAP_CONTENT,  
                                            LayoutParams.WRAP_CONTENT); 

                                    popupWindow.setFocusable(true);
                                    popupWindow.showAsDropDown(btnOpenPopup, -50, -70);

我在谷歌搜索过.我可以找到警报对话框的解决方案,但不能找到模态窗口的解决方案.如何解决这个问题?

I have searched in Google. I can find solutions for alert dialog box but not for modal window. How to fix this?

推荐答案

我遇到了同样的问题,但我最终使用父活动在弹出窗口中显示项目.您可以使用对话框来解决此问题,但如果您坚持在弹出窗口上.然后,这就是它的工作方式.
1.在您的父活动中创建自动完成文本视图,将其放置在您想要显示列表的任何位置并使可见性消失.
2.现在在popupwindow中,当您调用textwatcher或textchange时,将该数据适配器设置为父自动完成文本视图而不是popupwindow自动完成文本视图,并将可见性设置为可见.
3.它会在您输入任何字符时显示项目列表.

I faced the same problem but I end up using parent activity to display item in popup window.You can use dialog to solve this problem, but if you are insist on popupwindow. Then, this is how it gonna works.
1.create autocompletetextview in your parent activity,place it anywhere where you want to display list and make visibility to gone.
2.Now In popupwindow, when you call textwatcher or textchange, set that data adapter to parent autocomplete text view instead of popupwindow autocomplete textview and set visibility to visible.
3.It will display list of item as you type any character.

希望有所帮助!

这篇关于autocompletetextview 在弹出窗口中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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