Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Submitted By:

Amber Alam

Submitted To:
Sir Kashif

Roll No:
F20NDOCS1M01038

Subject
Mobile App Development
What is VIEW?

View is a basic building block of UI (User Interface) in android.


A view is a small rectangular box that responds to user inputs.
Eg: EditText, Button, Checkbox, etc
Android.view has a child class called View.
View refer to the android.view.View class, which is the base
class of all UI classes. android.view.View class is the root of the
UI class hierarchy. So from an object point of view, all UI
objects are View objects. Following are some of the common
View sub classes that will be used in android.
These are some of the view subclass available in android
 TextView
 EditText
 ImageView
 RadioButton
 Button
 ImageButton
 CheckBox
 DatePicker
 Spinner
 ProgressBar
What is setFocusable?

Public void setFocusable(intfocusable) is


the setFocusable method is a part of the Component class
and is used to specify whether a component can receive the
focus or not. The focus is an indication of which component is
currently ready to receive input from the user, such as
keyboard events.

The setFocusable() method in Java is used to set whether or


not a component can receive focus. By default, all components
are focusable. However, you can use
the setFocusable() method to change this behavior.
The setFocusable() method takes a boolean value as its
argument. If the value is true, the component will be
focusable. If the value is false, the component will not be
focusable.

You can also use the isFocusable() method to check whether


or not a component is focusable. The isFocusable() method
returns a boolean value. If the value is true, the component is
focusable. If the value is false, the component is not focusable.

The setFocusable() method is used to make a component (like


a button or text field) focusable or not focusable within a
container (such as a window or panel). When a component has
focus, it becomes the active element that accepts user input
events like keyboard presses.

What is requestFocus()?
The requestFocus() method in Java is used to set the focus to a
particular component. This method is part of the
java.awt.Component class and is often used in GUI
programming to direct the user's input to a specific
component, such as a text field, button, or other interactive
elements.
Syntax
component.requestFocus();
Where component is an instance of a class that extends
java.awt.Component (e.g., JButton, JTextField, etc.).

What is setOnFocusChangeListener?
The setOnFocusChangeListener() method is used in Android
development to set a listener that will be notified when the
focus state of a view changes. This method is part of the View
class in the Android SDK.
Syntax
view.setOnFocusChangeListener(new
View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// Your code here
}
});
By using setOnFocusChangeListener(), you can handle changes
in focus for views in your Android application, providing a
more interactive and responsive user experience
What is onFocusChanged()?
The onFocusChanged() method is used in the context of
custom views in Android to handle changes in focus state. This
method is a part of the View class and can be overridden
when creating custom views to handle specific actions when
the focus state changes.
Syntax

protected void onFocusChanged(boolean gainFocus, int


direction, @Nullable Rect previouslyFocusedRect)
By overriding onFocusChanged(), you can customize how your
view responds to focus changes, providing a more tailored
user experience in your Android application.

What is Activity.getCurrentFocus()?
The Activity.getCurrentFocus() method in Android is used to
retrieve the view in the current activity that currently has focus.
This can be particularly useful when you need to perform
operations on the focused view, such as hiding the keyboard
or validating user input
Syntax
View currentFocusView = activity.getCurrentFocus();
By using getCurrentFocus(), you can effectively manage focus-
related behaviors in your Android activities, enhancing the
user experience by providing appropriate responses to focus
changes.

What is ViewGroup.getFocusedChild()?
The ViewGroup.getFocusedChild() method in Android is used
to retrieve the direct child of the ViewGroup that currently has
focus. This method is particularly useful when you need to
determine which child view of a ViewGroup (such as a
LinearLayout, RelativeLayout, etc.) is currently focused.
Syntax
View focusedChild = viewGroup.getFocusedChild();

By using getFocusedChild(), you can effectively manage and


respond to focus changes within a ViewGroup, enhancing the
interactivity and usability of your Android applications.

You might also like