Android ListView- Error on setListAdapter & getListAdapter? -


i have following code in mainavtivity:

private dboperations datadboperation;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          datadboperation = new dboperations(this);         datadboperation.open();          list values = datadboperation.getallusersims();          // use simplecursoradapter show         // elements in listview         arrayadapter adapter = new arrayadapter(this,                 android.r.layout.simple_list_item_1, values);         setlistadapter(adapter);        }     public void addsim(view view) {          arrayadapter adapter = (arrayadapter) getlistadapter();          edittext text = (edittext) findviewbyid(r.id.edittext1);         simsclass stud = datadboperation.addsims(text.gettext().tostring());          adapter.add(stud);      }      public void deletesim(view view) {          arrayadapter adapter = (arrayadapter) getlistadapter();         simsclass sim = null;          if (getlistadapter().getcount() > 0) {             sim = (simsclass) getlistadapter().getitem(0);             datadboperation.deletesims(sim);             adapter.remove(sim);         }      }      public void addpassword(view view) {          arrayadapter adapter = (arrayadapter) getlistadapter();          edittext text = (edittext) findviewbyid(r.id.edittext2);         passwordclass stud = datadboperation.addpassword(text.gettext().tostring());          adapter.add(stud);      } 

and here layoun xml file:

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingbottom="@dimen/activity_vertical_margin"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     tools:context=".mainactivity" >      <textview         android:id="@+id/textview1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:layout_alignparenttop="true"         android:layout_marginleft="113dp"         android:text="textview" />      <edittext     android:id="@+id/edittext1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_alignparenttop="true"     android:ems="10" >          <requestfocus />     </edittext>      <button         android:id="@+id/addbtn"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_below="@+id/edittext1"         android:onclick="addsim"         android:text="add new" />      <button         android:id="@+id/deletebtn"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_torightof="@+id/addbtn"         android:layout_below="@+id/edittext1"         android:onclick="deletesim"         android:text="delete first" />      <listview         android:id="@android:id/list"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:layout_below="@+id/deletebtn" >     </listview>      <edittext         android:id="@+id/edittext2"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentright="true"         android:layout_below="@+id/addbtn"         android:ems="10" />      <button         android:id="@+id/passwordbtn"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_above="@android:id/list"         android:layout_torightof="@+id/edittext1"         android:onclick="addpassword"         android:text="@string/password" />  </relativelayout> 

error:
method setlistadapter(adapter) undefined type mainactivity.
method getlistadapter(adapter) undefined type mainactivity.

you need extend listactivity instead of activity. setlistadapter method of listactivity. same getlistadapter

http://developer.android.com/reference/android/app/listactivity.html


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -