. Net programmers play Android development-ListView Click Event, android-listview

Source: Internet
Author: User

. Net programmers play Android development-ListView Click Event, android-listview

Public class ListViewClickActivity extends Activity {

Private ListView lv;
SimpleAdapter adp; // define the adapter
Private List <map <string, object> mapList; // defines the data source.


Protected void onCreate (Bundle savedInstanceState)
{
// TODO Auto-generated method stub
Super. onCreate (savedInstanceState );
SetContentView (R. layout. listviewclicklay );
Lv = (ListView) findViewById (R. id. listView1 );

MapList = new ArrayList <map <string, object> ();
For (int I = 0; I <10; I ++)
{

Map <string, object> map = new HashMap <string, object> ();
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); // Specification
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 ();
 
}
});

}


 
} </String, object> </string, object> </map <string, object> </map <string, object>

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.