Skip to main content

Posts

Showing posts with the label android tutorial video

Save data into file

To save data into file in an android application, you have to follow the steps given bellow. 1. Create an object of the FileOutputStream class using the openFileOutput method.     Example :                      FileOutputStream fou = openFileOutput("text.txt", MODE_WORLD_READABLE);        Here text.txt is the name of the file. You can use any of the file opening mode    a.    MODE_PRIVATE  :  File is accessible by only the application that create it.    b.    MODE_APPEND :  Appending an existing file.    c.    MODE_WORLD_WRITABLE : Allow write permission to all the applications.  2. Get an object of the OutPutStreamWriter class using the FileOutputStream object.     Example:                  OutputStreamWriter osw = new OutputStreamWriter(fou); 3. Writ...

Registering events for views

Watch this on YouTube MainActivity.java package com.registerevent; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { Button b1, b2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b1 = (Button) findViewById(R.id.button1); b2 = (Button) findViewById(R.id.button2); b1.setOnClickListener(bListener); b2.setOnClickListener(bListener); } private OnClickListener bListener = new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub String label = ((Button)v).getText().toString(); Toast.makeText(getBaseContext(), "you click" +label, Toast.LENGTH_LONG).show(); } }; @Override public boolean onCreateOptionsMenu(Menu ...