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

Kotlin का उपयोग करके Android ListView में लाइन्स (डिवाइडर) कैसे हटाएं?

यह उदाहरण दर्शाता है कि Kotlin का उपयोग करके Android ListView में आइटम्स के बीच की लाइन्स (डिवाइडर) को कैसे हटाया जाता है।

चरण 1: नया प्रोजेक्ट बनाएं

Android Studio खोलें, File → New Project पर जाएं और नया प्रोजेक्ट बनाने के लिए सभी आवश्यक विवरण भरें।

चरण 2: activity_main.xml में ListView जोड़ें

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingStart="4dp"
    tools:context=".MainActivity">

    <ListView
        android:id="@+id/listView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" />

</RelativeLayout>

चरण 3: MainActivity.kt में डिवाइडर हटाएं

import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.ListView
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {
    lateinit var listView: ListView
    var mobilePhones = arrayOf("Samsung", "Iphone", "Nokia", "Alcatel", "Blackberry", "Oppo", "Sony")

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        title = "KotlinApp"

        listView = findViewById(R.id.listView)
        val adapter: ArrayAdapter<Any?> = ArrayAdapter(this, android.R.layout.simple_list_item_1, android.R.id.text1, mobilePhones)
        listView.adapter = adapter
        listView.divider = null
    }
}

चरण 4: XML में डिवाइडर हटाने का वैकल्पिक तरीका

<ListView
    android:id="@+id/listView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="@null"
    android:dividerHeight="0dp" />

चरण 5: AndroidManifest.xml कॉन्फ़िगर करें

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android"
    package="com.example.q11">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>

ऐप चलाएं

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

अतिरिक्त विकल्प: कस्टम डिवाइडर के लिए:

<!-- res/drawable/custom_divider.xml -->
<shape xmlns:android="https://schemas.android.com/apk/res/android" android:shape="rectangle">
    <size android:height="1dp" />
    <solid android:color="#CCCCCC" />
</shape>

<!-- उपयोग -->
listView.divider = ContextCompat.getDrawable(this, R.drawable.custom_divider)
listView.dividerHeight = 2
  1. Android में TreeSet का उपयोग करके ArrayList से डुप्लिकेट कैसे हटाएं और ListView में दिखाएं? Android में TreeSet का उपयोग करके ArrayList से डुप्लिकेट कैसे हटाएं और ListView में दिखाएं?

    Android में TreeSet का उपयोग करके ArrayList से डुप्लिकेट हटाना यह उदाहरण दर्शाता है कि Android में TreeSet का उपयोग करके ArrayList से डुप्लिकेट कैसे हटाएं और ListView में दिखाएं। चरण 1: नया प्रोजेक्ट बनाएं Android Studio में एक नया प्रोजेक्ट बनाएं: File → New Project पर जाएं और नया प्रोजेक्ट बनाने

  1. Android में LinkedHashSet का उपयोग करके ArrayList से डुप्लिकेट कैसे हटाएं और ListView में दिखाएं? Android में LinkedHashSet का उपयोग करके ArrayList से डुप्लिकेट कैसे हटाएं और ListView में दिखाएं?

    Android में LinkedHashSet का उपयोग करके ArrayList से डुप्लिकेट हटाना यह उदाहरण दर्शाता है कि Android में LinkedHashSet का उपयोग करके ArrayList से डुप्लिकेट कैसे हटाएं और ListView में दिखाएं। चरण 1: नया प्रोजेक्ट बनाएं Android Studio में एक नया प्रोजेक्ट बनाएं: File → New Project पर जाएं और नया प्रो

  1. एंड्रॉइड में ListView के बीच की लाइन्स कैसे हटाएं? एंड्रॉइड में ListView के बीच की लाइन्स कैसे हटाएं?

    एंड्रॉइड में ListView डिवाइडर लाइन्स हटाने का पूरा गाइड एंड्रॉइड ऐप डेवलपमेंट में अक्सर हमें ListView में आइटम्स के बीच दिखने वाली डिफ़ॉल्ट डिवाइडर लाइन्स को हटाने या कस्टमाइज़ करने की ज़रूरत पड़ती है। यह ट्यूटोरियल आपको स्टेप-बाय-स्टेप बताएगा कि कैसे setDivider(null) मेथड का उपयोग करके इन लाइन्स को