I'm currently developing Android applications on Android
I was getting tired of writing SomeView view = (SomeView) findViewById(R.id.view_name);
over and over again and decided to try and write a template for it.
I discovered Live Templates and decided to try and write on for this code snippet. I've managed to write the following:
= ($CLASS_NAME$) findViewById(R.id.$END$);
This will start the cursor at $CLASS_NAME$
and jump it to $END$
when I press Tab.
Which is nice but I'd like it to insert the first class name it finds, working backwards, and insert that into $CLASS_NAME$
. Thus writing SomeView view
and then calling the template would insert SomeView
at $CLASS_NAME$
.
I realise that the solution, if there is one, is probably to write a custom expression for the variable but I just don't know how to go about that.
I don' think you easily make a backward reference, but you can try someting like this:
$CLASS_NAME$ $END$ = ($CLASS_NAME$) findViewById(R.id.$END$);
or
$CLASS_NAME$ $VAR$ = ($CLASS_NAME$) findViewById(R.id.$END$);
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.