android - How to get a specific value which is displayed in ListView? -


in project, i've database in i've table called student. in table i've attributes roll_no, first_name, last_name, contact, class_name, password, email_id, gender. i'm reading students data database , showing "first_name, last_name , roll_no" in listview. code follows:

listview = (listview) findviewbyid(r.id.id_student_list);     db = new databasehelper(this);     arraylist<hashmap<string, string>> items = new arraylist<hashmap<string, string>>();      // reading contacts     log.d("reading: ", "reading students..");      list<student> studs = db.getallstudents();       (student cn : studs) {  // writing values map         hashmap<string, string> map = new hashmap<string, string>();         map.put("firstname", cn.getfirstname());         map.put("lastname", cn.getlastname());         map.put("roll", integer.tostring(cn.getroll_no()));          items.add(map);      }       // adding items listview     listadapter adapter = new simpleadapter(this, items,             r.layout.studname_listview, new string[] { "firstname", "lastname", "roll" },             new int[] {r.id.firstname, r.id.lastname, r.id.rollnumber }); <----      listview.setadapter(adapter); 

when click on particular listview item, want value going inside "r.id.rollnumber". i've implemented setonitemclicklistener on listview , it's working don't know how value shown on textview "r.id.rollnumber" whenever click on item of listview.

this listview elements xml file

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" >  <textview     android:id="@+id/firstname"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:padding="10sp"     android:text="sameer"     android:textsize="16sp"     android:textstyle="bold" > </textview>  <textview     android:id="@+id/lastname"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignbaseline="@+id/firstname"     android:layout_alignbottom="@+id/firstname"     android:layout_torightof="@+id/firstname"     android:text="waskar"     android:textsize="16sp"     android:textstyle="bold" />  <textview     android:id="@+id/rollnumber" <!-- value displayed in here -->     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignbaseline="@+id/lastname"     android:layout_alignbottom="@+id/lastname"     android:layout_alignparentright="true"     android:layout_marginright="22dp"     android:textstyle="bold" />  </relativelayout> 

hashmap? should create special class student info , override onitemclick method adapter


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -