2011-10-07 94 views
5

我有TableLayout,其中包含產品數量。每行包含代碼,描述數量,價格,折扣價值,.....取決於用戶輸入數量,折扣價值,折扣數量&其他一些數值也會計算。Android Softkeyboard將數值輸入edittext非常慢

當EDITTEXT軟鍵盤在用戶點擊後會來這一個還行,做工精細

我的問題是,當用戶按下數字鍵很慢於EditText上顯示。

比如我按3從鍵盤,7或8秒後只顯示它在那個特定的editText.How我可以縮短這個時間線...

這是我的產品形象:

ProductImage

請有人建議爲什麼會發生這種情況?

這樣的代碼:

 for (int i = initil; i <end; i++) { 
     ............. 
     ............ 
     final EditText txtQty = new EditText(this); 
      txtQty.setHeight(1); 
      txtQty.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 42)); 
      txtQty.setInputType(InputType.TYPE_CLASS_PHONE); 
      txtQty.setImeOptions(EditorInfo.IME_ACTION_DONE); 
      txtQty.setImeOptions(EditorInfo.IME_ACTION_NEXT); 
      txtQty.setSelectAllOnFocus(true); 
      txtQty.setTextSize(9); 
      txtQty.setHint("0.0"); 
    //  txtQty.setOnEditorActionListener(new DoneOnEditorActionListener()); 
//   txtQty.setHighlightColor(R.color.green); 
      tr.addView(txtQty); 

      InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
      mgr.showSoftInput(txtQty, InputMethodManager.SHOW_IMPLICIT); 

      mgr.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,InputMethodManager.HIDE_IMPLICIT_ONLY); 
      ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(txtQty.getWindowToken(), 0); 

      txtQty.setOnEditorActionListener(new OnEditorActionListener() { 
       public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
        Log.i("KeyBoard" ,"Inside the Edit Text"); 
        ............................. 
     } }); 
+0

檢查並減少tablelayout中的行,...... – viv

+0

你檢查過真實的設備..? –

+0

@Viv目前第一頁包含10條記錄。我不能減少更多,因爲有些客戶有超過400條記錄。所以,如果我們decalre循環的一面,是否有可能獲得外面的行值? (我想不是)。如果我們在外面宣佈它的確定。 – Piraba

回答

4

檢查這個代碼動態tablelayout:

的main.xml:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#C0C0C0"> 

    <RelativeLayout 
    android:layout_width="fill_parent" android:paddingBottom="20dip" 
    android:layout_height="fill_parent" 
    android:background="#C0C0C0"> 

    <TableLayout android:id="@+id/contact_table" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/contact_info_title" 
     android:layout_marginTop="10dp" 
     android:background="@drawable/bgwhite_selector"> 
     </TableLayout> 
</RelativeLayout> 
</ScrollView> 

要添加TableLayout的內容使用XML文件:

<?xml version="1.0" encoding="utf-8"?> 
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   android:id="@+id/lays" 
      android:layout_width="wrap_content" android:background="@color/white" 
      android:layout_height="wrap_content" android:orientation="vertical"> 

<TableRow android:background="@color/white" android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 

<TextView android:text=">" 
      android:textSize="18dip" android:textStyle="bold" android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:id="@+id/arrowText"/> 
    </TableRow> 

</LinearLayout> 

後創建sepearate行的佈局在Java代碼中添加此:

contact_table = (TableLayout)findViewById(R.id.contact_table); 

LayoutInflater inflater = getLayoutInflater(); 

for(int i = 0; i < contact_count ; i++) { 
LinearLayout row = (LinearLayout)inflater.inflate(R.layout.table_row,contact_table, false); 
TextView text = (TextView)row.findViewById(R.id.text); 
text.setText(list_data.get(i).summary); 
contact_table.addView(row); 
    } 

for(int i=0;i<contact_table.getChildCount();i++){ 
final View row=contact_table.getChildAt(i); 
row.setOnClickListener(new OnClickListener(){ 
    @Override 
    public void onClick(View v){ 
     // TODO Auto-generated method stub 
     row_id=contact_table.indexOfChild(row); 
    } 
}); 
} 

其次爲在循環越來越動態創建的錶行的點擊,在加入

msg_title_text.setOnEditorActionListener(new DoneOnEditorActionListener()); 

相應的動作監聽器:

class DoneOnEditorActionListener implements OnEditorActionListener { 
    @Override 
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
     if (actionId == EditorInfo.IME_ACTION_DONE) { 
      Log.v("*****************************", "Clicked"); 

      return true;  
     } 
     return false; 
    } 
} 
+0

感謝您的回答.... – Piraba

+0

@NagkeeranPiraba Cool – Venky

+0

+1爲更好的一個朋友。 –