my dear friends,
thanks for your advice, I too felt the same, and started learning myself
with out depending on others who are still the beginners like me, Thank you
for telling me franckly(but in the rude way),  Today onwards I will follow
typing it in full.
I am uable to find which method is used for what purpose to get the desired
output, so can you send me any material that helps me in learning the
Android application development.
The following is the code in which I'm not getting the desired output as
there must be some logical errors.

*DatabaseHelper.java:*
package com.db;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper
{
    public static final String DATA_BASE="Mydatabase.db";
    public static final String TABLE_NAME="Timetable";
    public static final int DATABASE_VERSION=1;

    public DatabaseHelper(Context context) {
        super(context, DATA_BASE, null, DATABASE_VERSION);
    }
    @Override
    public void onCreate(SQLiteDatabase db)
    {
        db.execSQL("CREATE TABLE "+TABLE_NAME+"(Name TEXT, Room NUMERIC,
Time Time");
    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int NewVersion)
    {

    }
}


*DatabaseUse.java:*
package com.db;

import android.app.Activity;
import android.app.AlertDialog;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class DatabaseUse extends Activity implements OnClickListener {
    Button submit, retrive;
    AlertDialog di;

    private SQLiteDatabase sqLiteDatabase;
    private SQLiteStatement sqLiteStatement;
    private String name, room, time;
    private static final String TABLE_NAME="Subject";

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        DatabaseHelper db=new DatabaseHelper(this);
            sqLiteDatabase=db.getWritableDatabase();
            sqLiteStatement=sqLiteDatabase.compileStatement("insert into
"+TABLE_NAME+ "(name, room, time) values (?,?,?)");
            submit.setOnClickListener(this);
            retrive.setOnClickListener(this);
    }
    @Override
    public void onClick(View v)
    {
        swith (v.getId())
        {
            case R.id.saveButton:
                Intent in=new Intent(getApplicationContext(),
DiaplayActivity.class);
                startActivity(in);
                break;
            case R.id.saveButton:

name=((EditText)findViewById(R.id.editText1)).getText().toString().trim();

room=((EditText)findViewById(R.id.editText2)).getText().toString().trim();

time=((EditText)findViewById(R.id.editText3)).getText().toString().trim();
                sqLiteStatement.bindString(1, name);
                sqLiteStatement.bindString(2, room);
                sqLiteStatement.bindString(3, time);
                sqLiteStatement.executeInsert();
                Toast.makeText(getApplicationContext(),"Data Saved Sami",
Toast.LENGTH_SHORT).show();
     }
}

*DisplayActivity.java:*
package com.db;

import java.util.ArrayList;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class DisplayActivity extends Activity {


    private ArrayList<String> arrayList = new ArrayList<String>();

    private SQLiteDatabase Mydatabase;
    ListView listView;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.display);
                listView=(ListView)findViewById(R.id.display);
        //openAndQueryDatabase

        try {
            DatabaseHelper db = new DatabaseHelper(this);
            //Open the database
            Mydatabase = db.getWritableDatabase();
            Cursor c = Mydatabase.rawQuery("SELECT * FROM Student", null);

            if (c != null ) {
                if  (c.moveToFirst()) {
                    do {
                        String Name = c.getString(c.getColumnIndex("Name"));
                        int age = c.getInt(c.getColumnIndex("TIME"));
                        String address =
c.getString(c.getColumnIndex("SUBJECT"));
                         arrayList.add("Name   : " + Name +"\n"+
                                    "Time       : " +age +"\n"+
                                    "Subject: " + address+"\n");
                    }while (c.moveToNext());
                }
            }
        } catch (SQLiteException se ) {
            Log.e(getClass().getSimpleName(),
                    "Could not create or " +"Open the database");
        } finally {
            if (Mydatabase != null)
            //Mydatabase.execSQL("DELETE FROM STUDENT");
                Mydatabase.close();
        }


        //displayResultList

        listView.setAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, arrayList));
    }
}


*TableActivity.java:*

package com.db;

import com.db.R;
import android.app.Activity;
import android.content.ContentValues;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class TableActivity extends Activity
{
    public class DisplayActivity extends Activity
    {
        Button b;
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            //getting UI from xml
            b=(Button)findViewById(R.id.display);
            final ImageView iv = null;

            //Adding listener
            b.setOnClickListener(new OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    //Business logic

                    et2.setText("Hello "+et1.getText());
                    Button add = (Button) findViewById(R.id.display);
                    add.setOnClickListener(new OnClickListener()
                    {

                        @Override
                        public void onClick(View v)
                        {
                            // TODO Auto-generated method stub

                            ContentValues cv = new ContentValues();

                            iv.getBackground();
                            cv.put("Name", name);

                            Log.i("DBSample", "Insert Successfully");
                            //    updateTable();
                        }
                    });
                }
            });
        }
        protected Drawable setWallpaper(int wntt) {
            // TODO Auto-generated method stub
            return null;
        }
    }
}

*main.xml:*
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android";
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    >

     <Button
         android:id="@+id/create"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="Create"
         android:onClick="layout/create"
         />

    <Button
        android:id="@+id/display"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Display"
        android:onClick="layout/display"

         />

   </LinearLayout>


*create.xml:*
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android";
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#ffffff" >


    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Time Table" android:textColor="#000000"/>

    <TableRow android:id="@+id/tableRow1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView android:text="Subject" android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#000000">
        </TextView>
        <EditText
            android:text="" android:id="@+id/editText1"
            android:layout_height="50px" android:layout_width="120px"/>
        </TableRow>


     <TableRow android:id="@+id/tableRow2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView android:text="Room" android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#000000">
        </TextView>
        <EditText
            android:text="" android:id="@+id/editText2"
            android:layout_height="50px" android:layout_width="120px">
        </EditText>
     </TableRow>

     <TableRow android:id="@+id/tableRow3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView android:text="Time" android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#000000">
        </TextView>
        <EditText
            android:text="" android:id="@+id/editText3"
            android:layout_height="50px" android:layout_width="120px">
        </EditText>
     </TableRow>

     <TableRow android:id="@+id/tableRow2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
            <Button android:text="Save"
                android:id="@+id/saveButton"
                android:layout_width="50px"
                android:layout_height="50px" >
                </Button>
   </TableRow>
   </LinearLayout>


*display.xml:*
<?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" >

  <ListView
      android:id="@+id/listView"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
  </ListView>

  <TableLayout
      android:id="@+id/tableLayout1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content" >

      <TableRow
          android:id="@+id/tableRow1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" >
      </TableRow>

      <TableRow
          android:id="@+id/tableRow2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" >
      </TableRow>

      <TableRow
          android:id="@+id/tableRow3"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" >
      </TableRow>

      <TableRow
          android:id="@+id/tableRow4"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" >
      </TableRow>
  </TableLayout>
</LinearLayout>

-- 
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

Reply via email to