View myView = findViewById(R.id.my_view); String className = myView.getClass().getName(); Log.d(TAG, "Class name: " + className);
if (myView.getClass() == Button.class) { // Do something if myView is a Button } else { // Do something else if myView is not a Button }
public class MyCustomView extends View { // Constructor and other methods omitted for brevity @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // Draw something on the canvas } }This code snippet defines a new custom View class named `MyCustomView` that extends the base View class and overrides the `onDraw()` method to perform some custom drawing on the canvas. The custom view can be added to a layout or used directly in code. Package library: `com.yourcompany.yourapp.views` (assuming the app has a package name of `com.yourcompany.yourapp`)