autocompletetextview不工作里面弹出窗口 [英] autocompletetextview not working inside popup window
问题描述
我是新来的Android和我试图整合自动完成文本视图
里面的弹出窗口。但是,自动完成动作不灵弹出的窗口内。如果我把自动完成文本视图之外弹出自动完成的作品就好了。
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 $ C $弹出窗口的C:
<?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 code:
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?
推荐答案
@覆盖 公共无效的onCreate(包savedInstanceState){ super.onCreate(savedInstanceState); 的setContentView(R.layout.activity_my);
@Override public void 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);
}});
}
这篇关于autocompletetextview不工作里面弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!