开发者

Application Lags

I have an android application that allows users to create edit text dynamically. However, it seems that whenever I have more than 5 edit text the typing process gets really lagging.

It goes by having a simple layout and a button. Whe开发者_运维知识库never the button is clicked it runs this code:

EditText editText = new EditText(context);
myLayout.addView(editText);

Is there any way I can make the code more efficient such that it won't be slow?


I don't know if it's a good idea as I don't know the nature of your app, but declaring views in the xmls is usually faster. Try declaring a bulk of editTexts - according to your average application needs and set their visibility to GONE until the user chooses to add an editText and then you check if you have a GONE view - you set it to visible, If not, you add it via code. Again, it all depends on your application's needs.


Try this:

EditText editText = new EditText(this);
myLayout.addView(editText);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜