Thursday, February 21, 2013

Add transparent theme to activity


In manifest

<activity

      . . . .  .
    android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"

. . . . . . .
> 
</activity>

How to create a splash screen


public class SplashActivity extends Activity {

                 private static String TAG = SplashActivity.class.getName();
                   private static long SLEEP_TIME = 5;    // Sleep for some time
                                   @Override
                   protected void onCreate(Bundle savedInstanceState) {
                      super.onCreate(savedInstanceState);
                      setContentView(R.layout.activity_splash);
                 
                      // Start timer and launch main activity
                      IntentLauncher launcher = new IntentLauncher();
                      launcher.start();
                   }
                 
                   private class IntentLauncher extends Thread {
                      @Override
                      /**
                       * Sleep for some time and than start new activity.
                       */
                      public void run() {
                         try {
                            // Sleeping
                            Thread.sleep(SLEEP_TIME*1000);
                         } catch (Exception e) {
                            Log.e(TAG, e.getMessage());
                         }
                 
                         // Start main activity
                         Intent intent = new Intent(SplashActivity.this,mainactivity.class);
                         SplashActivity.this.startActivity(intent);
                         SplashActivity.this.finish();
                      }
                   }
}


In manifest

<activity
           . . . . . .
             android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

. . . . . . . . . .
           >
        </activity>

Set editext input type programmatically

edittext1.setInputType(InputType.TYPE_CLASS_NUMBER);

Saturday, January 26, 2013

Create custom dialog :


code:

final Dialog d = new Dialog(myActivity.this);
d.setContentView(R.layout.mylayout);
d.setTitle("my title");
 final EditText edit = (EditText)d.findViewById(R.id.txtedit);
 Button btn = (Button)d.findViewById(R.id.txtbtn);
d.show();

layout:

<Button
        android:id="@+id/btnAdd"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
      />

    <EditText
        android:id="@+id/txtItem2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="text" />

Change color of alertdialog button


 Button b = dialogf.getButton(DialogInterface.BUTTON_NEGATIVE);
if(b != null){
   b.setBackgroundDrawable(getResources().getDrawable(R.drawable.loginbutton));
  b.setTextColor(getResources().getColor(android.R.color.white));
 }

Iterate through array values and insert to sqlite db:


String [] arrayA ={"a","b","c"};
Value[] adst =new Value[arrayA.length];
for( int i = 0; i < arrayA.length; i++)
{
String something = arrayA[i];
   Value dist =new Value();
    dist.setname(something);
     adst[i]=dist;
}

valuedao.insertInTx(adst);

Delete a row from sqlitetable:


 db.delete("Tablename","coloumnname"+"="+valuetocompare,null);