How does android implement actions in list view?

Source: Internet
Author: User

In the Problem description program, the listview contains three image buttons: play, detail, and buy. Each image button has its own action. In listview, how does one perform onclick action on each image button? Code used: [java] public class AndroidThumbnailList extends ListActivity {.......... public class MyThumbnaildapter extends ArrayAdapter <String> {public MyThumbnaildapter (Context context, int textViewResourceId, String [] objects) {super (context, textViewResourceId, objects ); // TODO Auto-generated constructor stub} public View getView (int position, View convertView, ViewGroup parent ){.........}} p Ublic void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); _ contentUri = MEDIA_EXTERNAL_CONTENT_URI; initVideosId (); setListAdapter (new MyThumbnaildapter (AndroidThumbnailList. this, R. layout. row, _ videosId) ;}} how to create an action in list view? Solution you need to create your own Adapter and then inflate the view you want to use. Then assign an OnClick listener to each image. Here is an example of my previous use [java] public class GroupListAdapter extends BaseAdapter {private List <Group> groups ;//... constructors here @ Override public int getCount () {return groups. size () ;}@ Override public Group getItem (int position) {return groups. get (position) ;}@ Override public long getItemId (int position) {return position ;}@ Override public View getView (final int position, View convertView, final ViewGroup parent) {final Group group = getItem (position); final View view; if (convertView = null) view = LayoutInflater. from (parent. getContext ()). inflate (R. layout. group, null); else view = convertView; view. setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {// do stuff when the rest of the view is clicked}); TextView TV = (TextView) view. findViewById (R. id. group_name); TV. setText (group. getName (); final CheckBox check = (CheckBox) view. findViewById (R. id. group_checkbox); check. setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {// do stuff when clicked}); return view ;}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.