Android TextView में toLowerCase() का उपयोग
यह उदाहरण दर्शाता है कि Android TextView में toLowerCase() मेथड का उपयोग करके टेक्स्ट को लोअरकेस (छोटे अक्षरों) में कैसे परिवर्तित किया जाता है।
चरण 1: नया प्रोजेक्ट बनाएं
Android Studio में File → New Project पर जाएं और आवश्यक विवरण भरकर एक नया प्रोजेक्ट बनाएं।
चरण 2: लेआउट XML में कोड जोड़ें
res/layout/activity_main.xml में निम्नलिखित कोड जोड़ें:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
xmlns:app="https://schemas.android.com/apk/res-auto"
xmlns:tools="https://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:hint="नाम दर्ज करें"
android:layout_height="wrap_content" />
<Button
android:id="@+id/click"
android:text="क्लिक करें"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:textSize="25sp"
android:layout_height="wrap_content" />
</LinearLayout>
उपरोक्त कोड में, हमने नाम के लिए EditText लिया है। जब उपयोगकर्ता बटन पर क्लिक करता है, तो यह डेटा लेता है और इसे लोअरकेस अक्षरों में परिवर्तित करता है।
चरण 3: MainActivity.java में कोड जोड़ें
package com.example.myapplication;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText name;
Button button;
TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = findViewById(R.id.name);
button = findViewById(R.id.click);
text = findViewById(R.id.textview);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String inputText = name.getText().toString().trim();
if (!inputText.isEmpty()) {
String lowerCaseText = inputText.toLowerCase();
text.setText(lowerCaseText);
} else {
name.setError("कृपया नाम दर्ज करें");
}
}
});
}
}
एप्लिकेशन चलाएं
अपने Android डिवाइस को कंप्यूटर से कनेक्ट करें। Android Studio में प्रोजेक्ट की एक्टिविटी फाइल खोलें और टूलबार से Run आइकन पर क्लिक करें। अपना मोबाइल डिवाइस चुनें और परिणाम देखें।

परिणाम: जब आप "KRISHNA" (अपरकेस) दर्ज करते हैं, तो यह "krishna" (लोअरकेस) लौटाता है।
मुख्य बिंदु
toLowerCase()String क्लास का एक बिल्ट-इन मेथड है- यह सभी अपरकेस अक्षरों को लोअरकेस में बदल देता है
- खाली स्ट्रिंग की जांच के लिए
trim().isEmpty()का उपयोग करें - उपयोगकर्ता अनुभव के लिए
setError()का उपयोग करके इनपुट वैलिडेशन करें