I am trying to create a Live-Template in Android Studio that will somewhat speed up creation of findViewById(...)
Part of it is self-learning, and part is curious in creating such live-templates.
I want to be able to type in the following...
Button find
+ (enter)
...and that should create something like this...
Button btnAdd = (Button) findViewById(R.id.btnAddition);
My current implementation has issues...
...and these issues stem from the use of completeSmart()
. Whenever you use completeSmart()
, the template ignores everything after that call and ends editing.
For example, If I moved the CAST
named-variable up one slot (above ID
) , then the cast would be automatically filled out and it would not let me easily edit ID
anymore. Same as below picture, but without btnAddition
. Just ...findViewById(R.id.);
With my current setup, I have CAST
on the very bottom so I can easily edit all of the named-variables; however, the use of completeSmart()
does not let the template end (Place the cursor by the $END$
marker - Line 29 in the picture below) when I am complete.
Instead, it places the cursor right after the cast , like so...
...when it should be placed on the start of the next line. This template does put a new line in, but the cursor does not go there at the end. Why?
So I want this...
1 ) Since I already but in Button
, I want to cast to be Button
. I should not have to type in in twice!
you should use method typeOfVariable()
you can change like this:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.