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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:25:36+00:00 2026-06-18T20:25:36+00:00

In my application I am having a list view,Now the problem is I want

  • 0

In my application I am having a list view,Now the problem is I want to get the marked positions
the code I am using is

        @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
            System.out.println("Entered Delete Button");
                String selected = "";
                int cntChoice = lv.getCount();
                System.out.println("The Number Of Contacts"+cntChoice);
                SparseBooleanArray x = lv.getCheckedItemPositions();
                System.out.println(x);
                for(int i = 0; i < cntChoice; i++){
                    if(x.get(i)) {
                        selected += lv.getItemAtPosition(i).toString() + "\n";  

                    }
                }   
                Toast.makeText(ViewSelectedContacts.this, 
                        selected, 
                        Toast.LENGTH_LONG).show();
            }
        });

The problem is SparseBooleanArray is not populating with the element
Also i had added

    android:choiceMode="multipleChoice"

in the listview..Somebody please help me to fin the problem

  • 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-18T20:25:37+00:00Added an answer on June 18, 2026 at 8:25 pm
      Try this code (works for me):
    
    // MainActivity
    
    public class MainActivity extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
           final ListView listTags = (ListView) findViewById(R.id.listPack);
           listTags.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, mStrings));
           listTags.setOnItemClickListener(new OnItemClickListener() {
    
               @Override
               public void onItemClick(AdapterView<?> parent, View view,
                       int position, long id) {
                   listTags.setSelection(position);
    //               Toast.makeText(getParent(), "hello", Toast.LENGTH_LONG).show();
               }
           });
    
    
    
        }
    
    
         private String[] mStrings = {
    
            "Comte", "Coolea", "Cooleney", "Coquetdale", "Corleggy", "Cornish Pepper",
            "Cotherstone", "Cotija", "Cottage Cheese", "Cottage Cheese (Australian)",
            "Cougar Gold", "Coulommiers", "Coverdale", "Crayeux de Roncq", "Cream Cheese",
            "Cream Havarti", "Crema Agria", "Crema Mexicana", "Creme Fraiche", "Crescenza",
            "Croghan", "Crottin de Chavignol", "Crottin du Chavignol", "Crowdie", "Crowley",
            "Cuajada", "Curd", "Cure Nantais", "Curworthy", "Cwmtawe Pecorino",
           };
    
    // Main xml
    
    <?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"
        android:orientation="vertical" >
    
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello" />
    
        <ListView
            android:id="@+id/listPack"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginBottom="5dip"
            android:layout_marginLeft="5dip"
            android:layout_marginRight="5dip"
            android:layout_weight="1" >
        </ListView>
    
            </LinearLayout>
    
    // list_item.xml // layout
    
    <?xml version="1.0" encoding="utf-8"?>
    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="10dp"
        android:textSize="16sp" >
    </TextView>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing Android Application. In which i am having list view with text
I am having a customized list view in my application, which is showing an
I am developing an application in android java Eclipse having two list view side
I have an ASP.NET MVC application. I am having multiple drop-down list in my
i have made an application having entity framewrok. It is wpf application, now it
In an application having UITabBarController , I want to implement following scenario: When user
I am trying to automate a web application having javascript. I am using WWW::Scripter
I am having a problem with using session variables. I have two controllers named
I've set up a little n-tier web application using MVP (Model View Presenter) in
I had added tabbar dynamically in my application which is having 3tabs. Now these

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.