6

我正在开发某种聊天应用程序,一切顺利,但我遇到了一个问题。EditText 滞后,每当我在 edittext 中键入一些字母时,我的 android 键盘都会在第二个或某个时间冻结。O 真的不知道要提供什么代码,因为它只是一个简单的 EditText 框。这是我的制作方法:

linforbutton.add(new LinearLayout(this));  //linear layout on the bottom os creen for edittext and button
    RelativeLayout.LayoutParams params =
      new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
      LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    linforbutton.get(x).setLayoutParams(params);
    linforbutton.get(x).setBackgroundColor(0xff426193);
    linforbutton.get(x).setOrientation(LinearLayout.HORIZONTAL);
    int padding_in_dp1 = 3;  
    final float scale1 = getResources().getDisplayMetrics().density;
    int padding_in_px1 = (int) (padding_in_dp1 * scale1 + 0.5f);
    linforbutton.get(x).setPadding(0, 0, 0, 0); 
    relmsg.get(x).addView(linforbutton.get(x));
    msginput.add(new EditText(this));
    msginput.get(x).setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f));
    msginput.get(x).setMaxLines(3);
    msginput.get(x).setMinLines(1);
    msginput.get(x).setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    msginput.get(x).setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
    msginput.get(x).setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    msginput.get(x).setImeOptions(EditorInfo.IME_ACTION_SEND);
    msginput.get(x).setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
    linforbutton.get(x).addView(msginput.get(x));
    btninput.add(new Button(this));
    btninput.get(x).setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    btninput.get(x).setText("Отпр.");
    int padding_in_dp2 = 20;  
    final float scale2 = getResources().getDisplayMetrics().density;
    int padding_in_px2 = (int) (padding_in_dp2 * scale2 + 0.5f);
    btninput.get(x).setPadding(padding_in_px2, 0, padding_in_px2, 0);
    linforbutton.get(x).addView(btninput.get(x)); 

我正在制作一些视图,所以我有一个 for 循环,不要查看数组。我尝试删除数组并只制作一个视图一个edittext一个按钮,但它不起作用。

4

1 回答 1

1

So it seems that your threads may conflict with each other. Look around your event listeners, maybe one of them holds the process. I had this problem a while ago with my GPS listeners (onLocationChanged).

I posted the data to the server from this listener and it just killed the application. After moving that block of code to a new thread it solved my problem.

于 2011-05-30T12:57:21.437 回答