ListView With Checkbox

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

ListView With Checkbox

Postby Raghav_s » Tue Sep 29, 2009 7:55 am

Here i am using simple_list_item_multiple_choice and then i m usin OnListItemClick..if i click this
checkbox in my Listview it will increment " 1 " and again if i unchecked the checkbox in the Listview it increments again " 1 " ....what i need means if i checked it should increment " 1 " and again if i Unchecked it should Decrement value" 1 "

can u tell anybody......... i think the Problem in OnListItemClick()....I dont know what should use Instead OnListItemClick().

Thanks in Advance....

Raghav.S

Here is My Code:
public class welcomeuser extends ListActivity {


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

final String[] options1 = new String[] {"Categories","Organizer"};

setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice,s));

getListView().setTextFilterEnabled(true);

final ListView list=getListView();
list.setItemsCanFocus(false);
list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);


}


protected void onListItemClick(ListView parent, View v, int position, long id) {

super.onListItemClick(parent, v, position, id);

int i=0;

if(position == 0)
{
i=i++;
}
else if(position == 1)
{
Toast.makeText(getBaseContext(),"You Clicked : is",Toast.LENGTH_SHORT).show();
}
}
}
Raghav_s
Junior Developer
Junior Developer
 
Posts: 18
Joined: Wed Sep 23, 2009 11:25 am
Location: Chennai

Top

Postby blackgin » Tue Sep 29, 2009 8:28 am

You need to use the getListView().isItemChecked(position) so you can know if it is checked or unchecked
User avatar
blackgin
Developer
Developer
 
Posts: 33
Joined: Tue Apr 21, 2009 1:21 pm

Again Problem in List view with Checkbox....

Postby Raghav_s » Tue Sep 29, 2009 8:39 am

Hi blackgin thanks for ur suggestion ....

in my ListView the Item is Checked...But my problem is if I click 2nd position in ListView it displays you Clicked in Toast message again if i Unchecked means again it displays You Clicked in Toast Message....I need the message should display only i Checked if i Unchecked means the message should not display.....but in my code the message always displaying even if i Unchecked.....

Pls reply me....

Thanks in Advance.....

Raghav.S
Raghav_s
Junior Developer
Junior Developer
 
Posts: 18
Joined: Wed Sep 23, 2009 11:25 am
Location: Chennai

Postby blackgin » Tue Sep 29, 2009 11:22 am

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. if (getListView().isItemChecked(position){
  3.  
  4. Toast.makeText(blablabla, "Checked!", blabla).show();
  5.  
  6. }
  7.  
  8. else if (!getListView().isIteChecked(position){
  9.  
  10. Toast.makeText(blabla, "UnChecked!", blabla).show;
  11.  
  12. }
  13.  
  14.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
User avatar
blackgin
Developer
Developer
 
Posts: 33
Joined: Tue Apr 21, 2009 1:21 pm

It Works Good....

Postby Raghav_s » Wed Sep 30, 2009 5:46 am

Hi blackgin thanks for ur suggestion.....It Works good....
Raghav_s
Junior Developer
Junior Developer
 
Posts: 18
Joined: Wed Sep 23, 2009 11:25 am
Location: Chennai

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 9 guests