• Skip to main content
  • Skip to primary sidebar
  • Home
  • WordPress
  • web Hosting
  • linux
  • mysql
  • nginx
  • apache2
  • devops

Raju Ginni

wordpress tutorials seo hosting etc

You are here: Home / tutorials / Android Studio tutorials syllabus Topics Course details #AndroidApplicationDevelopment / Custom List View

Custom List View

Custom List View

 

Table of Contents

Toggle
  • Creating a custom Adapter:
    • Setting the above adapter to ListView in Activity:

Creating a custom Adapter:

We have following steps to create a custom Adapter
1) Create a sub class of BaseAdapter
2) Declare the data objects we receive from Activity
3) Create a constructor with the declared objects
4) Override getCount method by passing the length of ListView
5) Override getItem method
6) Override getItemId method
7) Override getView method
i) Get LayoutInflater by using context
LayoutInflater inflater = LayoutInflater.from(context);
ii) Get View object from inflater by passing xml
View v = inflater.inflate(R.layout.list_item, parent, false);
iii) Identify all individual views
iv) Get data using position
v) Set the data to identified views

Ex:

public class MyAdapter extends BaseAdapter {
Context context;
String[] movies;
String[] cast;

public MyAdapter(Context context, String[] movies, String[] cast) {
this.context = context;
this.movies = movies;
this.cast = cast;
}

@Override
public int getCount() {
return movies.length;
}

@Override
public Object getItem(int position) {
return movies[position];
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.list_item, parent, false);

TextView textMovie = (TextView) view.findViewById(R.id.textView);
TextView textCast = (TextView) view.findViewById(R.id.textView2);

String movie = movies[position];
String castName = cast[position];

textMovie.setText(movie);
textCast.setText(castName);
return view;
}
}

Setting the above adapter to ListView in Activity:

ListView listView = (ListView)findViewById(R.id.listView);
String[] movies = {“Batman Triology”, “Harry Potter”, “Braveheart”, “The Patriot”, “Pompeii”, “Fast and Furious”,
“Die Hard”, “The Fifth element”, “X-Men”, “Transformers”, “Steve Jobs”};

String[] cast = {“Christian Bale”, “Daniel Radcliffe”, “Mel Gibson”, “Mel Gibson”, “Kit Harington”, “Paul Walker”,
“Bruce Willis”, “Bruce Willis”, “James McAvoy”, “Sam Witwicky”, “Michael fasbender”};

MyAdapter adapter = new MyAdapter(this, movies, cast);

listView.setAdapter(adapter);

Primary Sidebar

tutorials

  • Core Java Tutorial Free online
  • HTML & CSS Tutorials
  • Php tutorials
  • ubuntu tutorials installation download issues etc
  • redis install ubuntu 20.04 with wordpress php redis mysql configuration
  • [INTRO] Ethical hacking / cyber Security / Penetration testing Tutorial -{updates frequently}
  • Android Studio tutorials syllabus Topics Course details #AndroidApplicationDevelopment
    • Options Menu
    • JSON parsing
    • Handling Views
    • RelativeLayout
    • ActionBar
    • ListView
    • Custom List View
    • Dialogs
    • AlarmManager
    • Notifications
    • Vibration
    • WebView
    • Fragments Runtime
    • SQLiteDatabase
    • Bluetooth
    • WiFi
    • Google Maps
    • Handling Activity Back Button
    • AsyncTask
    • Runtime Permissions
    • Logging
    • Activity Lifecycle
    • Toast
    • Service
    • Database with Cursor Adapter
    • SharedPreferences
    • Location
    • Libraries
    • Webservices
    • Creating Activity class
    • Creating XML
    • Registering Activity in AndroidManifest.xml:
    • Steps for creating an Android application:
    • Handling button clicks
    • Identifying Views
    • Getting Text from Views
    • intent with Data
    • Intent
    • Resources Handling in Android
    • Intent with Result Data
    • Broad cast Receiver
    • Fragment
    • Handling Button click by using On Click Listener:
    • Material Design
    • RecyclerView
    • JSON
    • Rename Android Package [with images & video 2020]
    • migrating to androidx (The library & dependency matching)
    • adsense on webview , adsense & admob policies & implementation
  • AUdio Editing Background Noise removal (Audacity, Adobe Premiere Addition, Camtasia Filmora Windows Obs)
  • what is vpn vs proxy vs tor, http vs https, http2, tcp vs udp, kali linux sql source code injection
  • how to create a website free of cost on google
  • CCNA Syllabus pdf (CCNA / CCNP vs devops vs mcsa /MCSE)
  • Redis performance metrics & tuning for nginx apache ubuntu & debian
  • xampp tutorials 2021 installation errors fix wordpress phpmyadmin mysql apache
  • new relic installation linux (infrastructure agent , php, mysql , nginx)
  • new relic mysql install integration - 2 ways fix problems
  • new relic php agent install in 3 steps
  • aws load balancer tutorial
  • git branches merge fetch pull conflicts

hi i am raju ginni, primalry i manage wordpress websites on GCP cloud platform as a cloud engineer, and create content on passionate things.
you can follow me on youtbe

© 2025 - All Rights Reserved Disclaimer & Privacy Policy