What is the meaning of a dollar sign before an Android resource id

Greg Holst :

In the accepted answer of the following post(Android custom numeric keyboard) I found a syntax that I don't understand:

$(R.id.t9_key_0).setOnClickListener(this);

What does the dollar sign mean in front? Is it specifically related to Android resource ids or is more a general Java syntax? Search engine results didn't show any suitable results.

laalto :

It's a method call where the method name is $. The method is defined as follows in the code you linked:

protected <T extends View> T $(@IdRes int id) {
    return (T) super.findViewById(id);
}

The method is a helper that removes the need to cast the return type of findViewById(). It's no longer needed as of Android O as the platform findViewById() uses generics to do the same.

The name $ is likely inspired by jQuery.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=34925&siteId=1