【问题标题】:autocompletetextview not working inside popup window自动完成文本视图在弹出窗口中不起作用
【发布时间】:2014-01-23 08:58:58
【问题描述】:

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

弹窗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>

活动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);

我在 Google 中搜索过。我可以找到警报对话框的解决方案,但找不到模式窗口的解决方案。如何解决这个问题?

【问题讨论】:

  • popupWindow.showAsDropDown(btnOpenPopup, -50, -70);在这里尝试正值。
  • 我尝试了正值仍然无法正常工作。
  • 可能跑题了,但是为什么你在另一个布局里面有线性布局,然后是框架布局,你不能把它全部展平成一个布局吗?我问是因为它可能会导致问题,错误的布局会采取行动
  • 您找到解决错误的方法了吗?我遇到了同样的问题?
  • 有人解决了吗?

标签: android search popupwindow autocompletetextview


【解决方案1】:

@覆盖 公共无效 onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my);

    final Button btnOpenPopup = (Button)findViewById(R.id.openpopup);
    btnOpenPopup.setOnClickListener(new Button.OnClickListener(){

        @Override
        public void onClick(View arg0) {
            LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
            View popupView = layoutInflater.inflate(R.layout.activity_popup, null);

            final PopupWindow popupWindow = new PopupWindow(
                    popupView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, true);


            popupView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);

            final EditText text = (EditText)popupView.findViewById(R.id.editText); // to write Review notes

            final TextView txtRatingValue = (TextView)popupView.findViewById(R.id.txtRatingValue); // Rating Value

            final RatingBar   ratingBar = (RatingBar)popupView.findViewById(R.id.ratingBar);
            ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
                public void onRatingChanged(RatingBar ratingBar, float rating,
                                            boolean fromUser) {

                    txtRatingValue.setText(String.valueOf(rating));

                }
            });

            // popupView.addListenerOnRatingBar();


            Button  ok = (Button )popupView.findViewById(R.id.ok); // Database Codes to store the apps rating and review Data
            ok.setOnClickListener(new Button.OnClickListener() {

                @Override
                public void onClick(View v) {

                    Toast.makeText(MyActivity.this, "Reminder Nikhil Keshri's Database code to Be added here....", Toast.LENGTH_LONG).show();

                }
            });

            Button clear = (Button)popupView.findViewById(R.id.clear); // clearing button
            clear.setOnClickListener(new Button.OnClickListener() {

                @Override
                public void onClick(View v) {
                    text.setText("");
                    //  txtRatingValue.setText("0.0");

                }
            });


            // text.setBackgroundColor();
            Button close = (Button)popupView.findViewById(R.id.close); // closing the popup window
            close.setOnClickListener(new Button.OnClickListener() {

                @Override
                public void onClick(View v) {

                    popupWindow.dismiss();
                }
            });

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

        }});
}

【讨论】:

    【解决方案2】:

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

    希望有所帮助!

    【讨论】:

      猜你喜欢
      • 2018-12-15
      • 1970-01-01
      • 2016-04-08
      • 2014-09-30
      • 2013-05-31
      • 2022-01-19
      • 2011-12-03
      相关资源
      最近更新 更多