Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> Android

Android TextView में पैराग्राफ की संख्या कैसे गिनें?

Android TextView में पैराग्राफ की गणना करने का तरीका

यह उदाहरण दर्शाता है कि Android TextView में प्रदर्शित टेक्स्ट में पैराग्राफ की संख्या कैसे गिनी जाती है। डबल लाइन ब्रेक के आधार पर पैराग्राफ को विभाजित किया जाता है।

चरण 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:tools="https://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:gravity="center_horizontal" 
    android:layout_marginTop="100dp" 
    tools:context=".MainActivity"> 
    <TextView 
        android:id="@+id/text" 
        android:gravity="center" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"> 
    </TextView> 
</LinearLayout>

चरण 3: MainActivity.java में कोड जोड़ें

src/MainActivity.java में निम्न कोड जोड़ें:

package com.example.myapplication; 

import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.widget.TextView; 
import android.widget.Toast; 

public class MainActivity extends AppCompatActivity { 
    TextView text; 
    
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_main); 
        text = findViewById(R.id.text); 
        
        text.setText("Lorem Ipsum is simply dummy text of the printing and typesetting industry. " + 
            "Lorem Ipsum has been the industry's standard dummy text ever since the " + 
            "1500s, when an unknown printer took a galley of type and scrambled it to " + 
            "make a type specimen book. It has survived not only five centuries, but " + 
            "also the leap into electronic typesetting, remaining essentially unchanged. " + 
            "It was popularised in the 1960s with the release of Letraset sheets " + 
            "containing Lorem Ipsum passages, and more recently with desktop publishing " + 
            "software like Aldus PageMaker including versions of Lorem Ipsum."); 
        
        // डबल लाइन ब्रेक के आधार पर पैराग्राफ विभाजित करें
        String[] para = text.getText().toString().split("\r\n\r\n"); 
        Toast.makeText(MainActivity.this, "" + para.length, Toast.LENGTH_LONG).show(); 
    } 
}

ऐप चलाएं

अपने Android डिवाइस को कंप्यूटर से कनेक्ट करें। Android Studio में प्रोजेक्ट की एक्टिविटी फाइल खोलें और टूलबार से Run आइकन पर क्लिक करें। अपना मोबाइल डिवाइस चुनें और डिवाइस पर डिफ़ॉल्ट स्क्रीन देखें।

Android TextView में पैराग्राफ की संख्या कैसे गिनें?

  1. Android में JSON कैसे पार्स करें? Android में JSON कैसे पार्स करें?

    Android में JSONObject से सरल JSON पार्स करने का गाइड यह ट्यूटोरियल दिखाता है कि कैसे एक JSON स्ट्रिंग से JSONObject बनाकर नेस्टेड ऑब्जेक्ट्स से मान निकाले जाएं। चरण 1: नया प्रोजेक्ट बनाएं Android Studio में File → New Project चुनकर नया प्रोजेक्ट बनाएं। चरण 2: लेआउट फ़ाइल में कोड जोड़ें res/layout

  1. Android TextView में टेक्स्ट को जस्टिफाई कैसे करें? Android TextView में टेक्स्ट को जस्टिफाई कैसे करें?

    TextView में टेक्स्ट जस्टिफिकेशन Android 8.0 (API 26) से android:justificationMode=inter_word एट्रिब्यूट का उपयोग करके TextView में टेक्स्ट को जस्टिफाई (दोनों किनारों पर संरेखित) किया जा सकता है। चरण 1: नया प्रोजेक्ट बनाएं Android Studio में File → New Project चुनें (न्यूनतम API 26 या अधिक)। चरण 2

  1. Android TextView में टेक्स्ट को जस्टिफाई कैसे करें? Android TextView में टेक्स्ट को जस्टिफाई कैसे करें?

    यह उदाहरण दर्शाता है कि Android में TextView में टेक्स्ट को जस्टिफाई (दोनों किनारों पर अलाइन) कैसे किया जाता है। समस्या Android का स्टैंडर्ड TextView android:gravity=center_horizontal या left|right से जस्टिफिकेशन सपोर्ट नहीं करता। API 26 (Android 8.0) से android:justificationMode=inter_word उपलब्ध