Android UI Components in Hindi
Android में UI (User Interface) Components का उपयोग Screen पर Elements (जैसे Button, TextView, ImageView, EditText आदि) को दिखाने और User Interaction को Handle करने के लिए किया जाता है।
- UI Components को XML में Declare किया जाता है और Java/Kotlin Code के जरिए Control किया जाता है।
- इन Components का उपयोग करके अच्छे और Interactive Android Apps बनाए जा सकते हैं।
1. TextView (text दिखाने के लिए)
- TextView एक Android UI Component है, जो Screen पर Static Text को Show करता है।
- इसे User Edit नहीं कर सकता, यह सिर्फ Text Display करने के लिए होता है।
- यह Labels, Headings, Messages, या Instructions को दिखाने के लिए सबसे ज़्यादा Use होता है।
- TextView को XML में Declare किया जाता है और Java/Kotlin Code से Modify किया जा सकता है।
- यह Android के android.widget.TextView Class से आता है।
Example (TextView in XML)
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, Android!"
android:textSize="20sp"
android:textColor="#000000" />
Example (Java Code में Text Set करना)
TextView textView = findViewById(R.id.textView);
textView.setText("Welcome to Android!");
2. Button (buttom पर click करने के लिए)
Button Android का एक सबसे Common UI Component है, जिसका उपयोग User से Interaction के लिए किया जाता है। जब User किसी Button को Tap या Click करता है, तो एक Action Trigger होता है, जैसे:
- नई Activity Open करना
- Message Show करना (Toast/Dialog)
- Data Submit करना (Form Submission)
- Image या Text Change करना
Android में Button को XML (UI Design) और Java/Kotlin (Event Handling) में Define किया जाता है।
Example (Button in XML)
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me" />
Example (Java Code में Button का Event Handle करना)
Button button = findViewById(R.id.button);
button.setOnClickListener(v -> {
Toast.makeText(MainActivity.this, "Button Clicked!", Toast.LENGTH_SHORT).show();
});
3. EditText (User से Text Input लेने के लिए)
- EditText Android में एक UI Component है, जो User से Text Input लेने के लिए इस्तेमाल किया जाता है।
- यह TextView का Subclass है, लेकिन User इसमें Text को Edit कर सकता है।
- यह Forms, Search Box, Username & Password Input, Feedback Forms, और Data Entry Fields के लिए उपयोग किया जाता है।
Example (EditText in XML)
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your name" />
Example (Java Code में Text को Read करना)
EditText editText = findViewById(R.id.editText);
String userInput = editText.getText().toString();
Toast.makeText(MainActivity.this, "You entered: " + userInput, Toast.LENGTH_SHORT).show();
4. RadioButton (Multiple Options में से एक चुनने के लिए)
- RadioButton का उपयोग तब किया जाता है जब User को Multiple Options में से केवल एक चुनना हो।
- RadioButtons हमेशा एक Group में होते हैं और एक समय में केवल एक ही Option Select हो सकता है।
Example (RadioButton in XML)
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<adioButton
android:id="@+id/radioMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male" />
<RadioButton
android:id="@+id/radioFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />
</RadioGroup>
Example (Java Code में Selection को Read करना)
RadioGroup radioGroup = findViewById(R.id.radioGroup);
int selectedId = radioGroup.getCheckedRadioButtonId();
RadioButton selectedRadioButton = findViewById(selectedId);
Toast.makeText(MainActivity.this, "Selected: " + selectedRadioButton.getText(), Toast.LENGTH_SHORT).show();
5. CheckBox (Multiple Options Select करने के लिए)
- Checkbox का उपयोग तब किया जाता है जब User को एक से अधिक Options चुनने होते हैं।
- Example: "Terms & Conditions" Accept करने के लिए।
Example (CheckBox in XML)
<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Accept Terms & Conditions" />
Example (Java Code में CheckBox को Handle करना)
CheckBox checkBox = findViewById(R.id.checkBox);
if (checkBox.isChecked()) {
Toast.makeText(MainActivity.this, "Checkbox is Checked!", Toast.LENGTH_SHORT).show();
}
6. ImageView (Images को Show करने के लिए)
ImageView का उपयोग Screen पर Images Show करने के लिए किया जाता है।
Example (ImageView in XML)
<ImageView
android:id="@+id/imageView"
android:layout_width="200dp"
android:layout_height="200dp"
android:src="@drawable/sample_image" />
Example (Java Code में Image Change करना)
ImageView imageView = findViewById(R.id.imageView);
imageView.setImageResource(R.drawable.new_image);
7. ProgressBar (Loading Show करने के लिए)
ProgressBar का उपयोग तब किया जाता है जब कोई Task (जैसे File Downloading, Data Loading) चल रहा हो।
दो प्रकार के ProgressBar होते हैं:
- Indeterminate (Circular) → जब Task का Duration पता नहीं हो।
- Determinate (Horizontal) → जब Task का Duration पता हो।
Example (ProgressBar in XML)
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
Example (Java Code में ProgressBar Show/Hide करना)
ProgressBar progressBar = findViewById(R.id.progressBar);
progressBar.setVisibility(View.VISIBLE); // Show ProgressBar
progressBar.setVisibility(View.GONE); // Hide ProgressBar
Request
Leave a Comment
INITIALIZING...
INITIALIZING...
Comments Total: 0 comments