0

i want to get text of position of listview having check box is chacked .Listview comtains textview and checkbox coming from baseadapter

    holder = new ViewHolder();
            holder.full_name = (TextView) convertView
                    .findViewById(R.id.social_name);
            holder.social_network_pic = (ImageView)convertView.findViewById(R.id.social_image);
            holder.checkBox = (CheckBox)convertView.findViewById(R.id.social_check_box);


            convertView.setTag(holder);
            Log.e("Position=", "" + position);
            holder = (ViewHolder) convertView.getTag();
            String holderValue = socila_network_name_arraya_list.get(position).get("serviceLabel").toString();
            holder.full_name.setText(socila_network_name_arraya_list.get(position).get("serviceData").toString());
            int resID = getResources().getIdentifier(holderValue , "drawable", getPackageName());
            holder.social_network_pic.setImageResource(resID);
             holder.checkBox.setOnClickListener(CreatePost.this);
            holder.checkBox.isChecked();

after that i am not getting how to do this i need urgentaly:0

  • check the answer in the link http://stackoverflow.com/questions/16685366/customised-listview-using-arrayadapter-class-in-android/16686623#16686623. Original solution was given by Romain guy. I used the same in custom listview with custom adapter in the sample – Raghunandan May 23 '13 at 13:34
  • the link uses a string array. instead of string array you can use a arraylist. modify the answer in the link according to your needs – Raghunandan May 23 '13 at 13:43

1 Answers1

0

Try this Code

Below Code Initializing the ListView with Adapter

     list.setAdapter(new ArrayAdapter(Download_ReadyList.this,
                android.R.layout.simple_list_item_multiple_choice, item));
        for (int i = 0; i < result.length; i++) {
            list.setItemChecked(i, true);
        }

Below Code Getting the ListView to Check

int cntChoice = list.getCount();
String checked[] = new String[list.getCheckedItemCount()];
SparseBooleanArray sparseBooleanArray = list.getCheckedItemPositions();

            ArrayList<HashMap<String, String>> list_offline = new ArrayList<HashMap<String, String>>();
            int Count = 0;
            for (int i = 0; i < cntChoice; i++) {
                if (sparseBooleanArray.get(i) == false) {
                    checked[Count] = list.getItemAtPosition(i).toString();

                    Count++;
                }
            }
MDMalik
  • 3,951
  • 2
  • 25
  • 39
  • sir what is list? please explain i need urgently –  May 23 '13 at 13:44
  • list is your listview. Here in this example all the items in the listview are checked. so it finds out which item aren't marked (checked )==false – MDMalik May 23 '13 at 13:46
  • but my checkbox is through baseadapter –  May 23 '13 at 13:48
  • Sir what is cntChoice and EmpID? –  May 23 '13 at 13:51
  • @Blu exactly why i suggest you go through the link i posted below the comment.http://stackoverflow.com/questions/16636039/java-lang-classnotfoundexception-after-changing-nothing-in-the-project-but-upgra/16636127#16636127. check this or the link posted above – Raghunandan May 23 '13 at 13:52
  • @Blu you can also check tutorial @ 13.2 http://www.vogella.com/articles/AndroidListView/article.html#listadvanced_interactive – Raghunandan May 23 '13 at 13:56
  • @MDMalik sir getting this Exception :--java.lang.NoSuchMethodError: android.widget.ListView.getCheckedItemCount –  May 23 '13 at 13:58
  • @Blu http://developer.android.com/reference/android/widget/AbsListView.html#getCheckedItemCount() please do confirm that list is a ListView – MDMalik May 23 '13 at 14:08