How to make checkbox checked in the OnItemClickListener()?

I have a checkbox in my ListView row which looks like this.

===========================================
[CheckBox] [TextView] [TextView] [TextView]
===========================================

the xml code is here

<CheckBox
    android:id="@+id/course_search_checkbox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:clickable="false"
    android:focusable="false" />

And I have already made the checkbox not clickable and focusable so that the click event will be passed to the ListView.

What I want to do here is that when the user click the listview, make the CheckBox checked and add the clicked position of listview to an arraylist. So how can I make the CheckBox checked in an OnItemClickListener of ListView?

Help please, thanks.

Answers


You could add this code within your OnItemClickListener:

public void onItemClick(AdapterView parent, View view, int position, long id){
   CheckBox box = (CheckBox)view.findViewById(R.id.course_search_checkbox);
   box.setChecked(true);
}

Need Your Help

How to find the maximum of opening in all orientations at a point in an image?

matlab image-processing orientation line morphological-analysis

I need a bit of help. I am trying to segment out sort of zig-zag patterns in an image. I've an algorithm for this. For that I'm opening the image with a line structuring element. I want to perform

Missing data when submit with DateTime and editor template in MVC5

asp.net asp.net-mvc-5 mvc-editor-templates

I'm new in MVC. I use editor template for create 3 textbox for day, month, year for datetime type.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.