Android Adapter क्या है? | Types of Adapter with Example (Hindi)

Android Adapter क्या है? | Types of Adapter with Example (Hindi)

Adapter Android में एक bridge है जो data source (जैसे Array, List, Database) को UI component (जैसे ListView, RecyclerView) से connect करता है। यह data को UI में show करने का काम करता है।

Adapter क्यों use होता है?

  • Dynamic data UI में show करने के लिए।
  • Large data sets को efficiently manage करने के लिए।
  • UI और data के बीच communication के लिए।

Adapter के Types

  1. ArrayAdapter → जब data simple array या list में हो।
  2. BaseAdapter → Custom layouts और complex data के लिए।
  3. RecyclerView.Adapter → बड़े datasets और high performance UI के लिए।
  4. CursorAdapter → जब data database (SQLite) से आता हो।
  5. SimpleAdapter → Key-value pair data show करने के लिए।

Adapter कैसे काम करता है?

Adapter data source से data लेकर हर item के लिए एक View create करता है और उसे UI component को provide करता है।

Example: ArrayAdapter with ListView

Step 1: activity_main.xml

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

Step 2: MainActivity.java

ListView listView = findViewById(R.id.listView);
String[] names = {"Rahul", "Ankit", "Priya", "Neha"};

ArrayAdapter<String> adapter = new ArrayAdapter<>(
        this,
        android.R.layout.simple_list_item_1,
        names
);

listView.setAdapter(adapter);
    
✅ Output: ListView में names का list दिखाई देगा।

Real Life Examples

  • Contacts App → RecyclerView Adapter
  • WhatsApp Chats → RecyclerView Adapter
  • E-commerce Products List → Custom BaseAdapter या RecyclerView Adapter
© 2025 Android Tutorials in Hindi - All Rights Reserved

Comments

Popular posts from this blog

Git And GitHub Collaborators and teams

🎯 Retrofit से API Call कैसे करें – Android Studio में (Java के साथ Step-by-Step गाइड)

How to create React JS application