android - My custom CursorAdapter does not display the items -


i using custom cursoradapter , have values in db problem values not displaying in custom listview. searched in not find answer.

by debugging found out 2 methods in cursor adapter bindview() , newview() not executing constructor executing.i not sure happening overall. question why listview items not getting displayed ?

here code , posting relevant code if there additional code needed please comment edit accordingly.

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     //a listview object     notesview = (listview)findviewbyid(r.id.listview);     //an object of sqliteopenhelper class     dbhelper = new databasehelper(this);      //cursor object     passcursor = dbhelper.fetchallnotes();     // custom cursor adapter class object     datacursor = new customcursor(this,passcursor);     notesview.setadapter(datacursor);     notesview.setonitemclicklistener(this);     bar = (toolbar)findviewbyid(r.id.toolbar);     setsupportactionbar(bar); } 

here cursoradapter source code:

public class customcursor extends cursoradapter {     private static final string note_title = "title";     private static final string record_id = "_id";     private static final string record_date = "date";     private static final string delete_flag="deleteflag";     layoutinflater inflater;     textview tv, recordid, dateet;     linearlayout ll;     string gettext, existsrecordid;     long datevalue;     simpledateformat dateformatter;     string listviewheight;     context cont;     int getdeleteflag;     string listheightvalue;     linearlayout.layoutparams params;     cursor getcursor;      customcursor(context context, cursor c) {         super(context, c, 0);         cont= context;         getcursor= c;         //inflater = layoutinflater.from(context);         inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service);         dateformatter = new simpledateformat("dd-mm-yyyy hh:mm");     }       @override     public view newview(context context, cursor cursor, viewgroup parent) {         return inflater.inflate(r.layout.customlistview, parent, false);     }      @override     public void bindview(view view, context context, cursor cursor) {         getdeleteflag = cursor.getint(cursor.getcolumnindex(delete_flag));         ll = (linearlayout)view.findviewbyid(r.id.listviewlayout);         setlistviewheight(ll,context);         gettext = cursor.getstring(cursor.getcolumnindex(note_title));         existsrecordid = cursor.getstring(cursor.getcolumnindex(record_id));         datevalue = cursor.getlong(cursor.getcolumnindex(record_date));         date newdate = new date(datevalue);         recordid = (textview) view.findviewbyid(r.id.recordid);         tv = (textview) view.findviewbyid(r.id.content);         dateet = (textview) view.findviewbyid(r.id.date);         tv.settext(gettext.trim());         recordid.settext(existsrecordid);         dateet.settext(dateformatter.format(newdate));     }  } 

edit 1

here main layout,

<?xml version="1.0" encoding="utf-8"?>   <framelayout     android:layout_width="match_parent"     android:layout_height="match_parent"     android:id="@+id/fragplacement"     xmlns:android="http://schemas.android.com/apk/res/android">   <linearlayout 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"     android:gravity="top|left"     android:descendantfocusability="blocksdescendants"     tools:context="com.random.simplenotes.mainactivity">         <android.support.v7.widget.toolbar         xmlns:android="http://schemas.android.com/apk/res/android"         xmlns:app="http://schemas.android.com/apk/res-auto"         android:layout_width="match_parent"         android:layout_height="wrap_content"            android:id="@+id/toolbar"         >         </android.support.v7.widget.toolbar>       <listview         android:layout_width="match_parent"         android:clickable="true"         android:layout_height="match_parent"         android:id="@+id/listview"          android:scrollbars="vertical"         /> </linearlayout>  </framelayout> 

here layout listview item,

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"      android:layout_width="match_parent"     android:orientation="vertical"      android:layout_height="wrap_content"     android:descendantfocusability="blocksdescendants"     android:background="@color/peachpuff"      android:id="@+id/listviewlayout"     android:layout_margin="7dp">            <textview             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:textappearance="?android:attr/textappearancelarge"             android:text="here content.."             android:gravity="center"             android:id="@+id/content"             android:textcolor="@color/black"             android:focusable="false"             android:ellipsize="end"             android:lines="1"             android:maxlines="1"             android:layout_gravity="center_horizontal" />          <textview             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:textcolor="@color/black"             android:textappearance="?android:attr/textappearancesmall"             android:text="12/09/15"             android:layout_margin="10dp"             android:focusable="false"             android:id="@+id/date" />          <textview             android:layout_width="1dp"             android:layout_height="1dp"             android:visibility="gone"             android:focusable="false"             android:id="@+id/recordid" />   </linearlayout> 

code method setlistviewheight()

private void setlistviewheight(linearlayout ll, context con) {          sharedpreferences sp = preferencemanager.getdefaultsharedpreferences(con);          listheightvalue  = sp.getstring(con.getresources().getstring(r.string.listviewheightkey),constants.default_value_listview_height);           switch (listheightvalue)         {              case "tiny":                 params = new linearlayout.layoutparams(linearlayout.layoutparams.match_parent,200);                 ll.setlayoutparams(params);                  break;              case "medium":                params = new linearlayout.layoutparams(linearlayout.layoutparams.match_parent,220);                 ll.setlayoutparams(params);                  break;              case "large":                 params = new linearlayout.layoutparams(linearlayout.layoutparams.match_parent,250);                 ll.setlayoutparams(params);                  break;             default:                 params = new linearlayout.layoutparams(linearlayout.layoutparams.match_parent,150);                 ll.setlayoutparams(params);          }         } 

the problem haven't set orientation of linearlayout in main layout, defaults horizontal.

this means listview placed next toolbar, width of toolbar set match_parent, there no room left listview.

add following attribute linearlayout in activity_main.xml, listview placed below toolbar:

android:orientation="vertical" 

also, following call might need removed bindview():

setlistviewheight(ll,context); 

the height of listview set in xml, call might mess (i can assume, since haven't posted implementation of setlistviewheight()).


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -