java - An app to add , delete , and view data -


i have created app has in first activity (home) 1 button, goes next activity.
in next activity have put add, delete , list buttons, it's not working.

please me out

while deleting data should have check box select data in activity.

i using android studio 2.1.3

<listview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:id="@android:id/list"     android:layout_centerhorizontal="true"     android:layout_alignparenttop="true"     android:layout_above="@+id/btnadd" />  <button     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="list all"     android:id="@+id/btngetall"     android:layout_marginbottom="94dp"     android:layout_alignparentbottom="true"     android:layout_alignparentstart="true" />  <button     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="add"     android:id="@+id/btnadd"     android:layout_aligntop="@+id/btngetall"     android:layout_centerhorizontal="true" />   <button     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="delete"     android:id="@+id/btndel"     android:layout_below="@android:id/list"     android:layout_alignparentend="true" /> 

public class list_view extends listactivity implements android.view.view.onclicklistener{

button btnadd,btngetall,btndel;  textview student_id;   @override public void onclick(view view) {     if (view== findviewbyid(r.id.btnadd))     {          intent intent = new intent(this,studentdetails.class);         intent.putextra("student_id",0);         startactivity(intent);      }     else {          studentrepo repo = new studentrepo(this);          arraylist<hashmap<string, string>> studentlist = repo.getstudentlist();         if (studentlist.size() != 0) {             listview lv = getlistview();             lv.setonitemclicklistener(new adapterview.onitemclicklistener() {                 @override                 public void onitemclick(adapterview<?> parent, view view, int position, long id) {                     student_id = (textview) view.findviewbyid(r.id.student_id);                     string studentid = student_id.gettext().tostring();                      intent objindent = new intent(getapplicationcontext(), studentdetails.class);                     objindent.putextra("student_id", integer.parseint(studentid));                     startactivity(objindent);                 }             });            /* listadapter adapter = new simpleadapter( mainactivity.this,studentlist, r.layout.activity_view_student_entry, new string[] { "id","name"}, new int[] {r.id.student_id, r.id.student_name});             setlistadapter(adapter);*/              listadapter adapter = new simpleadapter(list_view.this, studentlist, r.layout.activity_view__student__entry, new string[]{"id", "name", "email", "age", "place", "phnumber"}, new int[]{r.id.student_id, r.id.student_name, r.id.student_email, r.id.student_age, r.id.student_place, r.id.student_phnumber});             setlistadapter(adapter);         } else {                 toast.maketext(this, "no student!", toast.length_short).show();             }     }      if (view== findviewbyid(r.id.btndel))     {          intent = new intent(this,delete.class);         startactivity(i);      }  }  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_list__view);       btnadd = (button) findviewbyid(r.id.btnadd);     btnadd.setonclicklistener(this);      btngetall = (button) findviewbyid(r.id.btngetall);     btngetall.setonclicklistener(this);      btndel = (button) findviewbyid(r.id.btndel);     btndel.setonclicklistener(this); } } 

try this.

android:descendantfocusability="blocksdescendants" 

or

in onitemclick try this.

string item = ((textview)view).gettext().tostring(); 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -