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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:53:36+00:00 2026-06-02T16:53:36+00:00

i have listview with checkboxes and save button. Whichever checkboxes i check and click

  • 0

i have listview with checkboxes and “save” button.
Whichever checkboxes i check and click save button, i want to save the data related to those checked rows into database
here is my code

public class CardDetailsAdapter extends BaseAdapter {    
private static ArrayList<CardDetails> searchArrayList;          
private LayoutInflater mInflater;       

 private boolean[] itemChecked =  new boolean[100];

public CardDetailsAdapter(Context context, ArrayList<CardDetails> results) {
     map = new HashMap<Integer, Boolean>();
    searchArrayList = results;
    mInflater = LayoutInflater.from(context);
}

public int getCount() {
    return searchArrayList.size();
}

public Object getItem(int position) {
    return searchArrayList.get(position);
}

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

public View getView(final int position, View convertView, final ViewGroup parent) {
    final ViewHolder holder;

    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.welcomelistview, null);
        holder = new ViewHolder();
        holder.bankName = (TextView) convertView.findViewById(R.id.BankNameID);
        holder.messages = (TextView) convertView.findViewById(R.id.messageID);
        holder.chkbox = (CheckBox) convertView.findViewById(R.id.chkBoxID);
        System.out.println("is checked==> " + holder.chkbox.isChecked());

        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }        
    holder.bankName.setText(searchArrayList.get(position).getBankName());
    holder.messages.setText(searchArrayList.get(position).getMessages());       
    holder.chkbox.setChecked(false);
    // save position and checking status into tag
    holder.chkbox.setTag(position);
    holder.chkbox.setOnClickListener(new OnClickListener() {            
        public void onClick(View v) {
             HashMap<Integer, Boolean> mSimpleAdapter = new HashMap<Integer, Boolean>();
             int p = (Integer) (v.getTag());
                if (holder.chkbox.isChecked() == true) {
                    itemChecked[Integer.valueOf(position)] = holder.chkbox.isChecked();  
                }else{
                    itemChecked[Integer.valueOf(position)] = holder.chkbox.isChecked();  
                 }

             mSimpleAdapter.put(p, itemChecked[position]);
             holder.chkbox.setChecked(itemChecked[position]); 
        }
    });
    return convertView;
}

static class ViewHolder {
    TextView bankName;
    TextView messages;
    CheckBox chkbox;
}}

and activity class

import com.ispl.CFSMS.helper.CardDetailsAdapter;
    public class WelcomePage extends Activity{
     CardDetailsAdapter mListAdapter;
    ArrayList<Integer> arList = new ArrayList<Integer>();
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.welcomepage); 
        final ArrayList<CardDetails> cardResults = GetCardDetails();
        final ListView welcomelist = (ListView) findViewById(R.id.welcomelistID);        
        welcomelist.setAdapter(new CardDetailsAdapter(this, cardResults));                      
        welcomelist.setOnItemLongClickListener(new OnItemLongClickListener() {
            public boolean onItemLongClick(AdapterView<?> a, View v, int position, long id) {
                Object o = welcomelist.getItemAtPosition(position);
                CardDetails fullObject = (CardDetails)o;
                Intent r=new Intent(WelcomePage.this , CardMenuActivity.class);
                r.putExtra("BankName", fullObject.getBankName());
                r.putExtra("CardNumber", fullObject.getCardNumber());
                startActivityForResult(r, position);
                return false;
            }
        });

        CheckBox checkbox = (CheckBox)findViewById(R.id.chkBoxID);
        Button saveTODbBtn = (Button)findViewById(R.id.saveID);
        saveTODbBtn.setOnClickListener(new OnClickListener() {              
            public void onClick(View v) {               
                //get the checkbox status and save related details into database
                Intent intent=new Intent(WelcomePage.this, BankProjectActivity.class);
                startActivity(intent);
            }
        });

    }    
 private ArrayList<CardDetails> GetCardDetails(){
        ArrayList<CardDetails> carddetailresults = new ArrayList<CardDetails>();        
         CardDetails sr1 = new CardDetails();

         sr1.setBankName("Select All");
         sr1.setCardNumber("");
         sr1.setMessages("");
         carddetailresults.add(sr1);

         sr1 = new CardDetails();    
         sr1.setBankName("HDFC Bank" +" "+ "xxxxx1234");
         sr1.setMessages("Messages: " + "10");
         carddetailresults.add(sr1);

         sr1 = new CardDetails();
         sr1.setBankName("ICICI" + " "+ "xxxxx2134");
         sr1.setMessages("Messages: 5");
         carddetailresults.add(sr1);

         sr1 = new CardDetails();
         sr1.setBankName("HSBC" + " "+ "xxxxx8796");
         sr1.setMessages("Messages: 2");
         carddetailresults.add(sr1);

         return carddetailresults;
 }} 

in Adaptar class i am able to get the status. but how do i save those status and get all the status in activity class so that on click of save button i save all the data related to those checked rows…?

  • 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-02T16:53:38+00:00Added an answer on June 2, 2026 at 4:53 pm

    Hi in the GetCardDetails() method add sr1.setSelected(true) or sr1.setSelected(false)

    in adapter add the following

      public static ArrayList<Boolean> itemChecked1 = null;  
      public CardDetailsAdapter( Context context, ArrayList<CardDetails> results) {
        super( context, R.layout.welcomelistview, R.id.BankNameID, results );
        searchArrayList = results;
        getContext = context;
        mInflater = LayoutInflater.from(context) ;
        itemChecked1 = new ArrayList<Boolean>();
        for (int i = 0; i < results.size(); i++) {
            itemChecked1.add(i, results.get(i).isSelected()); // initializes all items value with false         
        }
    }
    

    in getview

    holder.chkbox.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                CheckBox cb = (CheckBox) v;
                CardDetails planet = (CardDetails) cb.getTag();
                //planet.setSelected(cb.isChecked());
                if (holder.chkbox.isChecked()) {
                    itemChecked1.set(position, true);
                    holder.chkbox.setChecked(true);
                    planet.setSelected(true);
                } else if (!holder.chkbox.isChecked()) {
                    itemChecked1.set(position, false);
                    holder.chkbox.setChecked(false);
                    planet.setSelected(false);
                }
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView that contains 3 checkboxes per row. I want to set
I have a ListView with a couple of checkboxes. But if I want to
I want to save the state of a multiple choice listview checkbox's. I have
I have a ListView with checkboxes in it. When I click on a element
I have a ListView in ASP.NET where one column consists checkBoxes. I want the
I have ListView that uses a GridView to display several columns of data. Two
I have ListView which is saving all data to database. For adding i have
I have a listview and a button to remove items from that listview. The
I am working with listview in C# webapplication. My Problem is I want checked
I have an activity which have a button and a listview(with chechbox, image 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.