Ever wanted to know if there is something like an annotation on the android?

in general to get clicklistner implements View. OnClickListener

I need to write:

TextView text=(TextView)findviewbyid(R.id.text); text.setonclicklistener(this); 

Is it possible to replace all this code with annotation? really sometimes too much text arises from this

    1 answer 1

    There is such a wonderful thing as ButterKnife . It was created just for this purpose. Also significantly reduces the amount of code, and simplifies development. Try

    In your case, it will look like this:

     class ExampleActivity extends Activity { @BindView(text) TextView text; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.simple_activity); ButterKnife.bind(this); } @OnClick(R.id.text) public void submit() { // TODO something } } 
    • And there is a plugin in Android Studio. So that when you throw through setContentView. Does he create all these TextView ImageViews for you? - BluntHacker
    • I do not know, I think this is not quite the necessary thing. Try searching for ideas directly in the plugins - whalemare
    • Why same)). Suppose when you create a class in an android studio, you write the name of the class and a file is created with package com.fdsf.scdfdffd; /** * Created by fsdfs. */ public class asdsaad { } package com.fdsf.scdfdffd; /** * Created by fsdfs. */ public class asdsaad { } package com.fdsf.scdfdffd; /** * Created by fsdfs. */ public class asdsaad { } And there are classes with already ready 2 pages. Would you like it if it would all be empty. And you would write the same thing every time. Just the same thing, the same thing. - BluntHacker
    • You are confusing the concepts of patterns and dynamic code loading. Anyway, if my aktimti consists of 10 textviews in which there is static text, and only 1 is used in the code, then why do I need all 10 copies of a textview? This is a question for holivar and I think it can be discussed for a very long time) - whalemare