【问题标题】:Editext lost focus inside a ListView when click on it in android app在 Android 应用程序中单击时,Edittext 在 ListView 内失去焦点
【发布时间】:2014-11-20 10:51:14
【问题描述】:

我在 Listview 控件中有多个 EditText 控件。我已将数字键盘设置为 ListView 中的所有 EditText。但是,当我单击任何 EditText 时,第一个数字键盘会显示,而普通(字母)键盘会替换数字并且 EditText 会失去焦点。我必须再次单击 EditText 才能显示数字键盘。我该如何纠正这个问题。请建议。

【问题讨论】:

    标签: android listview android-edittext focus


    【解决方案1】:
    Please try this one.. Put the input type of edit text is either number or phone
    

    喜欢这个

         <EditText
                android:id="@+id/Tel"
                android:layout_width="350dp"
                android:layout_height="50dp"
                android:inputType="phone"
                android:textColor="#ffffff" />
    

    【讨论】:

      【解决方案2】:

      在你的listiview标签中添加descendantFocusablity="beforeDescendants"

      <ListView
         ....
          android:descendantFocusability="beforeDescendants"
          /> 
      

      并且还在清单文件中的activity标签下添加android:windowSoftInputMode="adjustPan"作为

      <activity
              android:name="yourlistviewactivity"
              android:windowSoftInputMode="adjustPan"
               >
          </activity>
      

      并添加

      listview.setItemsCanFocus(true);
      

      在您的活动中初始化列表视图之后。

      【讨论】:

      • 您好 Giru Bhai,感谢您的回答。但这对我不起作用。其实我有自定义 ListView 类。而不是我将它用作 ListView 控件。
      【解决方案3】:

      在您的 EditText xml 中添加“inputType='Number'”

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-06-04
        • 2011-01-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多