2014-02-20 50 views
4

我得到了一個ListView,使用BaseAdapter填充。 在ListView項有一個數字的EditText:EditText奇怪的行爲在ListView BaseAdapter

... 
      <EditText 
       android:id="@+id/edit_quantita" 
       android:layout_width="50dp" 
       android:layout_height="30dp" 
       android:layout_gravity="center" 
       android:layout_marginTop="5dp" 
       android:background="@drawable/edit_quantita" 
       android:gravity="center_vertical|center_horizontal" 
       android:inputType="number" 
       android:text="1" 
       android:textColor="#fff" 
       tools:ignore="HardcodedText" > 

      </EditText> 
... 

當我在此挖掘的EditText數字鍵盤提示一瞬間,然後它突然一個規則字符鍵盤覆蓋。如果我嘗試在此鍵盤上寫入內容,則不會在任何地方顯示文本。 奇怪的是,如果我再次點擊Editext,它的行爲應該像它應該那樣,只顯示工作數字鍵盤。

我該怎麼辦?

回答

5

EditText的實現在ListView中使用時有很多缺陷。嘗試添加這段代碼在您的onCreate()

int apiVersion = android.os.Build.VERSION.SDK_INT; 
if (apiVersion >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) 
      getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); 
else 
      getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); 
+0

它工作正常。非常感謝 – MikeKeepsOnShine

0

你可以嘗試以下方法:

  • 檢查您是否有可能與數字一個重疊另一個的EditText。
  • 只用數字EditText創建一個新的活動,看看是否發生了同樣的情況。
  • 檢查活動的代碼,以查看是否在運行時修改了某些內容。我不認爲你可以通過代碼改變EditText類型,但也許別的東西正在修改它的行爲。

希望它有助於調試問題。