Posts

Showing posts from April, 2017

Audio Insertion

1. Add audio into res -> raw folder 2. In Activity class, add the below code to your class where you wish to play sound - MediaPlayer ring = MediaPlayer. create (MainActivity. this , R.raw. applause ); ring.start();

Butter Knife: ease to bind view in activity

ButterKnife is an open source that eases the way to bind view in activity class. Below is the example: 1. In build gradle,           compile  'com.jakewharton:butterknife:8.5.1' annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1' 2. Suppose there are two buttons having id -  android :id= "@+id/hiBtn"   android :id= "@+id/byeBtn" 3. In activity .java class,     a. Initialize your binding button variable as- @BindView (R.id. hiBtn ) Button hiBtn ; @BindView (R.id. byeBtn )       Button bye Btn ;     b.         For Activity class, in onCreate() method, ButterKnife. bind ( this );         For Fragment class, in onCreateView() method View view = inflater.inflate(R.layout.fancy_fragment, container, false ); ButterKnife.bind( this , view);    c.  And the button click event as, @OnClick (R.id. hiBtn ) public void sayHi(Button hiBtn) { hiBtn.setText( "He