






































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







































































ANGUCHETTYPALAYAM, PANRUTI – 607 110
Develop an application that uses GUI components, Font and Colors DATE : AIM : To develop an android application that uses GUI Components, Font and colors. ALGORITHM:
protectedvoidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); finalTextView t1 = (TextView)findViewById(R.id.textView1); Button b1 = (Button)findViewById(R.id.button1); b1.setOnClickListener(newView.OnClickListener() { publicvoidonClick(View view) { t1.setTextSize(font); font = font+4; if(font==40) font = 20; } }); Button b2 = (Button)findViewById(R.id.button2); b2.setOnClickListener(newView.OnClickListener() { publicvoidonClick(View view) { switch(i) { case 1: t1.setTextColor(Color.parseColor("#0000FF")); break; case 2: t1.setTextColor(Color.parseColor("#00FF00")); break; case 3: t1.setTextColor(Color.parseColor("#FF0000")); break; case 4: t1.setTextColor(Color.parseColor("#800000")); break; } i++; if(i==5) i = 1; } }); } }
Thus, the program for android application GUI Components, Font and colors was executed successfully.
Develop an application that uses Layout Managers and Event Listeners DATE : AIM : To develop an android application that uses Layout Managers and event listeners. ALGORITHM:
Button clear = (Button)findViewById(R.id.button2); clear.setOnClickListener(newOnClickListener() { publicvoidonClick(View v) { try { txtData1.setText(""); txtData2.setText(""); } catch(Exception e) { Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_SHORT).show(); } } }); } } activity_main.xml <RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/relativeLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent">
android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_below="@+id/linearLayout1">
Thus, the program for android application that uses layout managers and event listeners was executed successfully.
Write an application that draws basic graphical primitives on the screen DATE : AIM : To develop an android application that draws basic graphical primitives on the screen. ALGORITHM:
android:layout_width="match_parent" android:layout_height="match_parent">
Thus, the program for android application that draws basic graphical primitives on the screen. was executed successfully.
Button Insert , Delete , Update , View , ViewAll ; SQLiteDatabase db ; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout. activity_main ); Rollno =(EditText)findViewById(R.id. Rollno ); Name =(EditText)findViewById(R.id. Name ); Marks =(EditText)findViewById(R.id. Marks ); Insert =(Button)findViewById(R.id. Insert ); Delete =(Button)findViewById(R.id. Delete ); Update =(Button)findViewById(R.id. Update ); View =(Button)findViewById(R.id. View ); ViewAll =(Button)findViewById(R.id. ViewAll ); Insert .setOnClickListener( this ); Delete .setOnClickListener( this ); Update .setOnClickListener( this ); View .setOnClickListener( this ); ViewAll .setOnClickListener( this ); // Creating database and table db =openOrCreateDatabase( "StudentDB" , Context. MODE_PRIVATE , null ); db .execSQL( "CREATE TABLE IF NOT EXISTS student(rollnoVARCHAR,nameVARCHAR,marks VARCHAR);" ); } public void onClick(View view) { // Inserting a record to the Student table if (view== Insert ) { // Checking for empty fields if ( Rollno .getText().toString().trim().length()==0|| Name .getText().toString().trim().length()==0|| Marks .getText().toString().trim().length()==0) { showMessage( "Error" , "Please enter all values" ); return ; } db .execSQL( "INSERT INTO student VALUES('" + Rollno .getText()+ "','" + Name .getText()+ "','" + Marks .getText()+ "');" ); showMessage( "Success" , "Record added" ); clearText(); } // Deleting a record from the Student table if (view== Delete ) { // Checking for empty roll number if ( Rollno .getText().toString().trim().length()==0) { showMessage( "Error" , "Please enter Rollno" ); return ;
Cursor c= db .rawQuery( "SELECT * FROM student WHERE rollno='" + Rollno .getText()+ "'" , null ); if (c.moveToFirst()) { db .execSQL( "DELETE FROM student WHERE rollno='" + Rollno .getText()+ "'" ); showMessage( "Success" , "Record Deleted" ); } else { showMessage( "Error" , "Invalid Rollno" ); } clearText(); } // Updating a record in the Student table if (view== Update ) { // Checking for empty roll number if ( Rollno .getText().toString().trim().length()==0) { showMessage( "Error" , "Please enter Rollno" ); return ; } Cursor c= db .rawQuery( "SELECT * FROM student WHERE rollno='" + Rollno .getText()+ "'" , null ); if (c.moveToFirst()) { db .execSQL( "UPDATE student SET name='" + Name .getText() + "',marks='" + Marks .getText() + "' WHERE rollno='" + Rollno .getText()+ "'" ); showMessage( "Success" , "Record Modified" ); } else { showMessage( "Error" , "Invalid Rollno" ); } clearText(); } // Display a record from the Student table if (view== View ) { // Checking for empty roll number if ( Rollno .getText().toString().trim().length()==0) { showMessage( "Error" , "Please enter Rollno" ); return ; } Cursor c= db .rawQuery( "SELECT * FROM student WHERE rollno='" + Rollno .getText()+ "'" , null ); if (c.moveToFirst()) { Name .setText(c.getString(1)); Marks .setText(c.getString(2)); } else { showMessage( "Error" , "Invalid Rollno" );