. Net programmers play Android development-ListView Click Event

Source: Internet
Author: User

. Net programmers play Android development-ListView Click Event

As we all know, ListView is used to display the data list. Each list consists of list items. If we click to select a list, what should I do if I want to get the details in the list or open a new window to pass the list information? This section demonstrates the click event of ListView. Through this section, we will have a deeper understanding of ListVIEW. Let's take a look at it first.

 

The Demo code is as follows:

Main layout File

 

 

List item layout File

 

 

Background code

 

Public class ListViewClickActivity extends Activity {private ListView lv; SimpleAdapter adp; // defines the private List of the adapter.
 
  
> MapList; // define the data source protected void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stubsuper. onCreate (savedInstanceState); setContentView (R. layout. listviewclicklay); lv = (ListView) findViewById (R. id. listView1); mapList = new ArrayList
  
   
> (); For (int I = 0; I <10; I ++) {Map
   
    
Map = new HashMap
    
     
(); Map. put (code, encoding: 1000 + I); map. put (name, name: Ipad + I); map. put (price, price: + I); map. put (model, unit: + I); mapList. add (map);} adp = new SimpleAdapter (ListViewClickActivity. this, mapList, R. layout. listdetail, new String [] {code, name, price, model}, new int [] {R. id. tvcode, R. id. tvname, R. id. tvprice, R. id. tvmodel}); lv. setAdapter (adp); lv. setOnItemClickListener (new OnItemClickListener () {@ Override public void onItemClick (AdapterView
     Arg0, View arg1, int arg2, long arg3) {TextView tname = (TextView) arg1.findViewById (R. id. tvname); // name TextView tmodel = (TextView) arg1.findViewById (R. id. tvmodel); // type TextView tprice = (TextView) arg1.findViewById (R. id. tvprice); // unit price TextView tcode = (TextView) arg1.findViewById (R. id. tvcode); // code Toast. makeText (getApplicationContext (), current product name: + tname. getText () +, encoding: + tcode. getText (), 30 ). show ();}});}}
    
   
  
 



 

Related Article

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.