New views should be created in newView:
http://developer.android.com/reference/android/widget/CursorAdapter.html#newView(android.content.Context,
android.database.Cursor, android.view.ViewGroup)
setContentView is supposed to be only called once in onCreate, with the
activity's layout (which should include your ListView).
Finally, running a query inside bindView is wrong. You're supposed to
run your query outside of the adapter (in the activity's onCreate, for
example) and pass the resulting Cursor to the adapter.
http://thinkandroid.wordpress.com/2010/01/09/simplecursoradapters-and-listviews/
-- Kostya
09.12.2010 10:09, pramod.deore пишет:
Hi, I am developing one small application to understand how
CursorAdapter works. In this application I have a main activity in
taht I am showing some buttons, after click on "showlist" button
another activity named as ShowSwitchesList is called it is extended
from CursorAdapter. Now in this class I want to read the database and
display 2 columns from that table to list. If suppose in my list.xml
file i have 2 textview ,but when I write like this then I got error as
R.id.item cannot be resolved.
I am confused where to put setContentView(R.layout.list); My code is
like this
public class ShowSwitchesList extends CursorAdapter
{
String SAMPLE_DBNAME = "NewHomeAutoDataBase";
private final String LOADTYPE_TABLE_NAME = "LoadTable";
SQLiteDatabase sampleDB = null;
private Cursor mCursor;
private Context mContext;
private final LayoutInflater mInflater;
public ShowSwitchesList(Context context, Cursor c)
{
super(context, c,true);
// TODO Auto-generated constructor stub
mInflater = LayoutInflater.from(context);
mContext = context;
}
@Override
public void bindView(View view, Context context, Cursor cursor)
{
final LayoutInflater inflater = LayoutInflater.from(context);
// TODO Auto-generated method stub
Cursor c = sampleDB.rawQuery("SELECT SwitchName,LoadType FROM "
+LOADTYPE_TABLE_NAME , null);
String st = c.getString(c.getColumnIndex("SwitchName"));
TextView t = (TextView) view.findViewById(R.id.item); //here I
got
error
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent)
{
// TODO Auto-generated method stub
return null;
}
}
I had not written whole logic yet.
--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en