Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android EditText lagging when typing text

Im developing some sort of chat application, all goes wellm but im stuck with one problem. EditText lags, my android keyboard gets freezed on second or some whenever I type some letter in edittext. O din't really know what code to provide, because it's just a simple EditText box. Here's how i make it:

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)); 

Im making some views so i have a for loop, dont look at the arrays. I tried removing arrays and making only one view one edittext one button and it didn't work.

like image 455
artouiros Avatar asked May 30 '11 07:05

artouiros


1 Answers

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.

like image 159
Adam Arold Avatar answered Oct 21 '22 02:10

Adam Arold