Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7850401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:50:11+00:00 2026-06-02T18:50:11+00:00

I am trying to add a checkbox in a customized listview but don’t know

  • 0

I am trying to add a checkbox in a customized listview but don’t know how.

I have the following codes:

ListObject.java

package br.com.eduvm.xurrascalc;

public class ListObject {

private String texto;
private int iconeRid;

    public ListObject() {

}

    public ListObject(String texto, int iconeRid) {

    this.texto = texto;
    this.iconeRid = iconeRid;
}

public int getIconeRid() {

    return iconeRid;
}

public void setIconeRid(int iconeRid) {

    this.iconeRid = iconeRid;
}

public String getTexto() {

    return texto;
}

public void setTexto(String texto) {

    this.texto = texto;
}
}

ListAdapter.java

package br.com.eduvm.xurrascalc;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

public class ListAdapter extends BaseAdapter {

private LayoutInflater mInflater;
private ArrayList<ListObject> itens;

public ListAdapter(Context context, ArrayList<ListObject> itens) {

    // Itens que preencheram o listview
    this.itens = itens;

    // responsavel por pegar o Layout do item.
    mInflater = LayoutInflater.from(context);
}

public int getCount() {

    return itens.size();
}

public ListObject getItem(int position) {

    return itens.get(position);
}

public long getItemId(int position) {

    return position;
}

public View getView(int position, View view, ViewGroup parent) {

    ListObject item = itens.get(position);

    view = mInflater.inflate(R.layout.itens_lista, null);

    ((TextView) view.findViewById(R.id.text)).setText(item.getTexto());
    ((ImageView) view.findViewById(R.id.imagemview)).setImageResource(item.getIconeRid());

    return view;
}
}

List.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
        android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:padding="5sp" >

        <ImageView
            android:id="@+id/imagemview"
            android:layout_width="wrap_content"
            android:layout_height="match_parent" />

        <TextView
            android:id="@+id/text"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginLeft="5sp"
            android:gravity="center_vertical"
            android:textColor="#FFF" />

    </LinearLayout>

</LinearLayout>

How could I do to insert a checkbox in the items in this list?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:50:15+00:00Added an answer on June 2, 2026 at 6:50 pm

    This would be the layout for each individual row in your list

    <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
    
    <CheckBox 
        android:id="@+id/lstChkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:id="@+id/lstText"
        android:textSize="30px"
        android:layout_weight="1" />
    
    <ImageView 
        android:id="@+id/listImage"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />
    

    You main list activity layout will look something like this:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    
    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:drawSelectorOnTop="false"
        android:choiceMode="multipleChoice"
        />
    

    Your class which extends BaseAdapter getView method will somethings like this:

    public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder vHolder = null;

        if (convertView != null)
            vHolder = (ViewHolder) convertView.getTag();                                // convertView is been recycled
        else {
            convertView = (View) mInflater.inflate(R.layout.list_item, null);           // Set content of new View with list_item.xml
    
            vHolder = new ViewHolder();
            vHolder.checkBox = ((CheckBox) convertView.findViewById(R.id.lstChkbox));   // Getting pointers
            vHolder.textView = ((TextView) convertView.findViewById(R.id.lstText));
            vHolder.imageView = ((ImageView) convertView.findViewById(R.id.listImage));
    
            vHolder.checkBox.setOnCheckedChangeListener(this);                          // Setting Listeners
    
            convertView.setTag(vHolder);
        }
    
        vHolder.checkBox.setId(position);                                               // This is part of the Adapter APi
        vHolder.textView.setId(position);                                               // Do not delete !!!
        vHolder.imageView.setId(position);
    
    
        if (mItems.get(position).getChecked()) {                                        // Setting parameters for the View from our mItems list
            vHolder.checkBox.setChecked(true);
        } else {
            vHolder.checkBox.setChecked(false);
        }
    
        vHolder.textView.setText(mItems.get(position).getText());
        vHolder.imageView.setImageDrawable(mItems.get(position).getmImage());
    
        return convertView;
    }
    
    public static class ViewHolder {
        CheckBox checkBox;
        TextView textView;
        ImageView imageView;
    }
    
    /*
     * Ok for this test but Toast are going to show every time the row comes into View
     */
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        Log.d(TAG, "Checked");
        int position = buttonView.getId();
    
        if (isChecked) {
            mItems.get(position).setChecked(true);
            Toast.makeText(context, mItems.get(position).getText(), Toast.LENGTH_LONG).show();
        } else {
            mItems.get(buttonView.getId()).setChecked(false);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add a CheckBox to every item in my ListView . I
I'm trying add vertical lines to my grid. I have found some examples but
I am trying to add a custom data-required attribute to an asp Checkbox control,
Trying to add a class object into a List using reflection, but when invoking
Im trying to add a directory foo to my repo, but there are some
I am trying to add a checkbox to a List component in my application
I'm trying to use checkboxes to add users to a specific group but I'm
I'm trying to use jQuery to add dynamic Add/Remove row function, but I meet
I am trying to add a class when a checkbox is checked in Safari
I'm trying to add a checkbox to a column on a web grid, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.