简体   繁体   English

弹出键盘时,在列表视图中显示/隐藏Edittext变得不可见

[英]Show/hide Edittext inside listview becomes invisible when keyboard pops up

I have a custom Listview whose adapter extends BaseAdapter class. 我有一个自定义Listview,其适配器扩展了BaseAdapter类。 Inside every row in listview there is an invisible EditText. 在列表视图的每一行中,都有一个不可见的EditText。 it get visible to only particular row which has been click and on rest of the row it remains invisible.Problem comes when I touch edittext to get keyboard, as soon as keyboard appears, listview gets recycle and edittext again become invisible. 它仅在已单击的特定行上可见,而在其余行上则保持不可见。当我触摸edittext来获取键盘时,问题就来了,一旦键盘出现,listview就被回收,edittext再次变得不可见。 I am looking for a solution in which either keyboard comes with focus on edittext as soon as that row is selected or edittext does not disapear when keyboard is poped-up.Following is the adapter I am using: 我正在寻找一种解决方案,其中选择该行后键盘要么专注于edittext,要么弹出键盘时不消失edittext。以下是我使用的适配器:

this is my adapter xml file saved_option_adapter_content.xml 这是我的适配器xml文件save_option_adapter_content.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/lineItem"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    >
<TextView 
    android:id="@+id/textLine"
    android:layout_height="wrap_content"
    android:layout_marginLeft="70dp"
    android:layout_marginTop="15sp"
    android:layout_marginBottom="5sp"
    android:textSize="14sp"
    android:paddingTop="-5dp"
    android:layout_width="wrap_content"/>

<LinearLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_alignParentRight="true">

<EditText 
    android:id="@+id/edittext_qty"
    android:visibility="invisible"
    android:gravity="center"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:singleLine="true"
    android:maxLength="4"
    android:textSize="14sp"
    android:inputType="numberPassword"
    android:focusable="true"
    android:textColor="@android:color/black"
    android:hint="cvv"/>
</LinearLayout>
</RelativeLayout>

and this is my getView Method: 这是我的getView方法:

public View getView(final int position, View convertView, final ViewGroup parent) 
             { 
             final ViewHolder holder;
                 if (convertView == null) 
                     {
                         convertView = mInflater.inflate(R.layout.saved_options_adapter_content, null);
                         holder = new ViewHolder();
                         holder.textLine = (TextView) convertView.findViewById(R.id.textLine);
                         holder.Edittext = (EditText) convertView.findViewById(R.id.edittext_qty);

                        editTextList.add(holder.Edittext);                  
                         convertView.setOnClickListener(new OnClickListener() 
                         {
                                 @Override
                                 public void onClick(final View v) 
                                     { 
selected_Txt="";
                                     if(view==null || view!=v){
                                     v.post(new Runnable() {
                                            @Override
                                            public void run() {
                                                view=v;
                                                  ViewHolder holder = ((ViewHolder)v.getTag()); 
                                                 holder.Edittext.setVisibility(View.VISIBLE);
                                                  holder.Edittext.requestFocus();
                                                 holder.Edittext.setCursorVisible(true);
                                                holder.Edittext.setFocusable(true); 
                                               if(selectedHolder != null ){
                                                selectedHolder.Edittext.setVisibility(View.INVISIBLE);
                                                }
                                                selectedHolder = holder; 
                                            }
                                        }); 
                                     }
                                     }
                         });

                         convertView.setTag(holder);
                     } 
                 else 
                     {
                     holder = (ViewHolder) convertView.getTag();
                    ((ViewHolder)convertView.getTag()).Edittext.setTag(title.get(position));
                     }

                  convertView.setTag(holder);
                 return convertView;
             } 

I don't see listview in your code. 我在您的代码中看不到listview。 Maybe ArrayAdapter can help you: http://developer.android.com/reference/android/widget/ArrayAdapter.html 也许ArrayAdapter可以帮助您: http : //developer.android.com/reference/android/widget/ArrayAdapter.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM