Hi I had write a code that read data from database and display it using SimpleCursorAdapter. Here is my .java file public class SimpleCursorDemo extends ListActivity {
String SAMPLE_DBNAME = "NewHomeAutoDataBase"; private SimpleCursorAdapter myAdapter; SQLiteDatabase sampleDB = null; private final String LOADTYPE_TABLE_NAME = "LoadTable"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); sampleDB = this.openOrCreateDatabase(SAMPLE_DBNAME, MODE_PRIVATE, null); createTableForLoadType(); try { Cursor c = sampleDB.rawQuery("SELECT _id,LoadType,SwitchName FROM " +LOADTYPE_TABLE_NAME , null); startManagingCursor(c); String[] columns = new String[] {"LoadType", "SwitchName"}; int[] names = new int[] {R.id.room, R.id.switch1}; myAdapter = new SimpleCursorAdapter(this, R.layout.main, c, columns,names); } catch (Exception e) { e.printStackTrace(); } } public void createTableForLoadType() { try { sampleDB.execSQL("CREATE TABLE IF NOT EXISTS " + LOADTYPE_TABLE_NAME + " (_id INTEGER PRIMARY KEY autoincrement ,SwitchName varchar,LoadType int,FedType int,Speed int);"); sampleDB.execSQL("INSERT INTO " + LOADTYPE_TABLE_NAME + " Values (null,'Tube Light','0',null,null);"); sampleDB.execSQL("INSERT INTO " + LOADTYPE_TABLE_NAME + " Values (null,'kElectric Bell','0',null,null);"); sampleDB.execSQL("INSERT INTO " + LOADTYPE_TABLE_NAME + " Values (null,'Bulb','1',null,null);"); System.out.println ("After inserting data to LoadType"); } catch (Exception e) { e.printStackTrace(); } } } and my main.xml is like <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ImageView android:src="@drawable/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Room Name: " /> <TextView android:id="@+id/room" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Switch Name: " /> <TextView android:id="@+id/switch1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout> </LinearLayout> But when I run application then it doesn't show any output. It also not throw any exception. I think my problem is in xml file. Anyone know what's wrong in this? -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en