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 7560143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:49:20+00:00 2026-05-30T12:49:20+00:00

I am really stuck here. What I want is not simple (for me), however

  • 0

I am really stuck here. What I want is not simple (for me), however I’ve been programming android a year now.
What I want is a listview with an imageview, a textview, a checkbox, and another textview in each row.
Let’s have a textview and a checkbox first in the layout.
Based on this tutorial I managed to do that (there are a lot, but this seems to be the best for me). I have a listview populated with textviews and checkboxes.

This is the result:

enter image description here

This is how I get the text of textview I click on:

 textView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            TextView tv = (TextView) v ;
            String text_of_clicked_textview = tv.getText().toString();
            Log.i("TAG", "" + text_of_clicked_textview);
        }
    });

So When I click on Mercury, I get Mercury in the text_of_clicked_textview variable.

But how can i check which checkbox I clicked on? E.g I click on the 3rd checkbox, I want to now it is in the row of Earth. Best would be if I get to know both the text of textview in the row of the listview(Earth) and and number of the item (3).

I guess I have to set an onClickListener on the checkbox but what next?

checkBox.setOnClickListener( new View.OnClickListener() {
      public void onClick(View v) {
        CheckBox cb = (CheckBox) v ;

      }
    });
  • 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-05-30T12:49:22+00:00Added an answer on May 30, 2026 at 12:49 pm

    This is XML for Custom Row in ListView :

        <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
    
            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/camera_icon" />
    
            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />
    
            <CheckBox
                android:id="@+id/checkBox1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="" 
         />
    
    </LinearLayout>
    

    This is Complete Activity in which List is implemented :
    Just Copy this Activity for test then understand code. Place one listview in main Activity

    package com.DemoTest;
    
    import java.util.ArrayList;
    import java.util.List;
    import java.util.zip.Inflater;
    
    import android.app.Activity;
    import android.content.Context;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.ViewGroup;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.ArrayAdapter;
    import android.widget.BaseAdapter;
    import android.widget.CheckBox;
    import android.widget.ImageView;
    import android.widget.ListView;
    import android.widget.TextView;
    
    public class CustomList extends Activity implements OnClickListener
    {
    
        ListView listView;
        ArrayList<EachRow> list=new ArrayList<CustomList.EachRow>();
        EachRow each;
        @Override
        protected void onCreate(Bundle savedInstanceState) 
        {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            String[] color={"red","green","blue","white","yellow","cyan","purple","grey",
                    "0red","0green","0blue","0white","0yellow","0cyan","0purple","0grey",
                    "1red","1green","1blue","1white","1yellow","1cyan","1purple","1grey"};
            for(String str : color)
            {
                each=new EachRow();
                each.text=str;
                list.add(each);
            }
            listView=(ListView)findViewById(R.id.listView1);
            listView.setAdapter(new MyAdapter(this, 0, list)); 
            //listView.setOnItemClickListener(this);
        }
        class MyAdapter extends ArrayAdapter<EachRow>
        {
            LayoutInflater inflat;
            ViewHolder holder;
            public MyAdapter(Context context, int textViewResourceId,
                    ArrayList<EachRow> objects) 
            {
                super(context, textViewResourceId, objects);
                // TODO Auto-generated constructor stub
                inflat=LayoutInflater.from(context);
            }
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                // TODO Auto-generated method stub
    
                if(convertView==null)
                {
                    convertView=inflat.inflate(R.layout.row_checkox, null);
                    holder=new ViewHolder();
                    holder.textView=(TextView)convertView.findViewById(R.id.textView1);
                    holder.image=(ImageView)convertView.findViewById(R.id.imageView1);
                    holder.check=(CheckBox)convertView.findViewById(R.id.checkBox1);
                    holder.check.setOnClickListener(CustomList.this);
                    convertView.setTag(holder);
                }
                holder=(ViewHolder) convertView.getTag();
                EachRow row= getItem(position);
                Log.d("size", row.text);
                holder.textView.setText(row.text); 
                holder.check.setChecked(row.checkBool); 
                holder.check.setTag(position);
                return convertView;
            }
    
            @Override
            public EachRow getItem(int position) {
                // TODO Auto-generated method stub
                return list.get(position);
            }
    
            private class ViewHolder
            {
                TextView textView;
                ImageView image;
                CheckBox check;
            }
        }
        private class EachRow
        {
            String text;
            boolean checkBool;
        }
    
    
    
        @Override
        public void onClick(View v) 
        {
            // TODO Auto-generated method stub
    
            EachRow row=list.get((Integer)v.getTag());
             row.checkBool=!row.checkBool;
             Log.d("item", "Item Click at "+(Integer)v.getTag()+" : "+row.text+" is "+row.checkBool); 
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have been stuck with this issue for a few days now, and really need,
Hey, I'm really stuck with my project here... I need to know when any
I've made my own tree data structure via classes. Now I'm stuck with really
I am stuck with something quite simple but really annoying: I have an xml
I'm stuck on what I think should be simple thing to do. I've been
Really stuck on trying to write code to unzip a file or directory on
I'm really stuck on why the following code block 1 result in output 1
I'm really stuck trying to find out how to force a programmatic refresh of
I'm really stuck trying to use java wrapper library for opencv's cvMatchTemplate. See this
I realize this question is pretty basic, but I'm really stuck. I have a

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.