Arrayadapter in Android to Create Simple Listview

ArrayAdapter in android to create simple listview

ArrayAdapter uses a TextView to display each item within it. Behind the scenes, it uses the toString() method of each object that it holds and displays this within the TextView. ArrayAdapter has a number of constructors that can be used and the one that you have used in your example is:

ArrayAdapter(Context context, int resource, int textViewResourceId, T[] objects)

By default, ArrayAdapter uses the default TextView to display each item. But if you want, you could create your own TextView and implement any complex design you'd like by extending the TextView class. This would then have to go into the layout for your use. You could reference this in the textViewResourceId field to bind the objects to this view instead of the default.

For your use, I would suggest that you use the constructor:

ArrayAdapter(Context context, int resource, T[] objects). 

In your case, this would be:

ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values)

and it should be fine. This will bind each string to the default TextView display - plain and simple white background.

So to answer your question, you do not have to use the textViewResourceId.

How to set ArrayAdapter to Listview - Android


ListAdapter customAdapter = new ListAdapter(this, R.layout.list_item,List<tempList>)


ListAdapter customAdapter = new ListAdapter(this, R.layout.list_item, tempList); 

REmove list just add tempList

How to Make a Custom ArrayAdapter for ListView

Make a Custom Adapter. Set that adapter to your listview. Your Adapter class should extend ArrayAdapter. In getView() inflate your custom xml with 3 textviews . Use a viewholder for performance.

Hers's an example Hers's a bit more to listview

how to set json parsed data in a listview and then adding search functionality in it. Have a look at the answer. I have used hashmap and displayed data in listview accordingly with search on listview items. Modify the same according to your needs.

how to create a custom array adapter in android studio to disable clicks on list view item

Instead of using a regular ListView use a custom one:

1) Create a CustomListView class:

public class CustomListView extends ListView{

//add these three constructors
public CustomListView(Context context){
public CustomListView(Context context , AttributeSet attrs){
super(context , attrs);
public CustomListView(Context context , AttributeSet attrs, int defStyleAttr){
super(context , attrs, defStyleAttr);

//handle the item click
public boolean performItemClick(View view , int position , long id){

//don't handle the click
return false;
//handle the click
return super.performItemClick(view, position, id);


  1. add the CustomListView that you created to your xml layout instead of ListView.

  2. replace:

    ListView listView = findViewById(.......);


    CustomListView listView = findViewById(.......);

2) remove these methods from your CustomAdapter class:

public boolean areAllItemsEnabled() {
return false;

public boolean isEnabled(int position) {
// return super.isEnabled(position);

3) handle the item click like that:

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, final View view, final int position, long id) {

poss = position + 1;
AlertDialog.Builder builder = new AlertDialog.Builder(viewFriends.this);
builder.setMessage("Please select to to edit, delete a friend or cancel");

// add the buttons
builder.setPositiveButton("Edit", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {

//.......keep whatever you have the same here


builder.setNeutralButton(" Delete", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {

//disable the view so that you won't receive clicks again


builder.setNegativeButton("Cancel", null);
AlertDialog dialog = builder.create();;


If you use the above implementation, then when you click delete button in alert dialog the item won't receive the click event the next time.

listview with arraylist,simple adapter in android



android:layout_height="60dp" >

android:layout_height="wrap_content" >



<?xml version="1.0" encoding="utf-8"?>

android:gravity="center_vertical" />


add in onCreate() of your activity file

ListView listView;

String[] from = { "php_key","c_key","android_key","hacking_key" };

ArrayAdapter arrayAdapter;

listView = (ListView) findViewById(;

arrayAdapter = new ArrayAdapter<>(this,R.layout.setlanguage,, from);


Related Topics

Leave a reply