In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces android how to use ListView to display data, the article is very detailed, has a certain reference value, interested friends must read it!
Effect picture
1. Define item first
2. Bind the data to listview through the adapter, and click on a row of data to display the number.
Method 1:
List data=new ArrayList (); for (Person person: persons) {HashMap hashMap=new HashMap (); hashMap.put ("id", person.getPersonId ()); hashMap.put ("name", person.getName ()); hashMap.put ("amount", person.getAmount ()); data.add (hashMap) } SimpleAdapter adapter=new SimpleAdapter (this,data,R.layout.item,new String [] {"id", "name", "amount"}, new int [] {R.id.personiddyR.id.nametheR.id.amount}); listView.setAdapter (adapter); listView.setOnItemClickListener (new OnItemClickListener () {@ Override public void onItemClick (AdapterView parent, View view, int position, long id) {ListView myListView= (ListView) parent) HashMap item= (HashMap) myListView.getItemAtPosition (position); Toast.makeText (DBActivity.this, item.get ("id"). ToString (), Toast.LENGTH_SHORT). Show ();}})
Method 2: use cursors
Cursor cursor=personService.getCursor (0,15); / requires that the primary key for designing a table with _ id in the field is _ id SimpleCursorAdapter cursorAdapter=new SimpleCursorAdapter (this,R.layout.item,cursor,new String [] {"_ id", "name", "amount"}, new int [] {R.id.personiddR.id.amount}); listView.setAdapter (cursorAdapter) ListView.setOnItemClickListener (new OnItemClickListener () {/ * parent currently clicked listview object * view current clicked entry * / @ Override public void onItemClick (AdapterView parent, View view, int position, long id) {ListView myListView= (ListView) parent; Cursor data= (Cursor) myListView.getItemAtPosition (position); / / move cursor int m=data.getInt (data.getColumnIndex ("_ id") based on position) Toast.makeText (DBActivity.this, String.valueOf (m), Toast.LENGTH_SHORT). Show ();}}); this is all the content of the article "how android uses ListView to display data". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.