How to add a ListView to a Fragment -


i writing code adding listview fragment.
, listview data retrieved class (by using arraylist).
can't add listview fragment.

here code.
guys, can suggest me do?

public class startfragment extends fragment {       datasource datasource;     arraylist<employee> arraylist;     listview listview;     customadapter adapter;     context context;      public startfragment() {      }      @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {         // inflate layout fragment          return inflater.inflate(r.layout.fragment_start, container, false);     }      @override     public void onactivitycreated(bundle savedinstancestate) {         super.onactivitycreated(savedinstancestate);         listview = (listview) getactivity().findviewbyid(r.id.listview);         arraylist = datasource.getallemployee();         adapter = new customadapter(context,arraylist);         listview.setadapter(adapter);     } } 

following startfragment layout code...

<framelayout 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"     tools:context="com.softmaker.gazi_opu.ourpresentation.startfragment">      <listview         android:layout_width="match_parent"         android:layout_height="match_parent"         android:id="@+id/listview"/>  </framelayout> 

and here custom layout listview items.

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent" android:layout_height="match_parent"     android:orientation="vertical"     >       <linearlayout         android:orientation="vertical"         android:layout_width="match_parent"         android:padding="20dp"         android:layout_height="wrap_content">          <textview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:textappearance="?android:attr/textappearancelarge"             android:text="name: "             android:id="@+id/name_textview" />          <textview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:textappearance="?android:attr/textappearancelarge"             android:text="designation: "             android:id="@+id/designationtextview" />          <textview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:textappearance="?android:attr/textappearancelarge"             android:text="salary: "             android:id="@+id/salarytextview" />     </linearlayout>  </linearlayout> 

change code in this

listview = (listview) getactivity().findviewbyid(r.id.listview); 

to this

listview = (listview) getview().findviewbyid(r.id.listview); 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -