Skip to main content

Posts

Showing posts with the label button click

Blinking TextView - Two Methods

METHOD 1 private void blink(){ final Handler handler = new Handler(); new Thread(new Runnable() { public void run() { int timeToBlink = 600; //in milissegunds try { Thread.sleep(timeToBlink); }catch (Exception e) { }handler.post(new Runnable() { public void run() { TextView txt = (TextView)findViewById(R.id.usage); if(txt.getVisibility() == View.VISIBLE) { txt.setVisibility(View.INVISIBLE); }else { txt.setVisibility(View.VISIBLE); } blink(); } }); } }).start(); } METHOD 2 T...

Calling a Service from Activity in Android

This is a service class: public class serv extends Service { private static final String TAG = "MyService"; AlertDialog alertDialog @Override public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } public void onCreate() { Toast.makeText(getApplicationContext(), "My Service Created",Toast.LENGTH_LONG).show(); } @Override public void onDestroy() { Toast.makeText(this, "My Service Stopped",Toast.LENGTH_LONG).show(); Log.d(TAG, "onDestroy"); //player.stop(); } @Override public void onStart(Intent intent, int startid) { Toast.makeText(this, "My Service Started",Toast.LENGTH_LONG).show(); Log.d(TAG, "onStart"); //player.start(); } } Call service from activity: public class MainActivity ...

How to use RadioButtonGroup in Android?

in xml page: < ?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" > < TextView android:id="@+id/tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Which company do you like the most?" android:textSize="25dp" android:textStyle="bold" /> < RadioGroup android:id="@+id/menu" android:layout_width="fill_parent" android:layout_height="wrap_content" android:checkedButton="@+id/lunch" android:orientation="vertical" > < RadioButton android:id="@+id/google" ...

ContextMenu in Android

Long click on the button to open the menu. in java class: public class ContextmenuActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button b=(Button)findViewById(R.id.button1); registerForContextMenu(b); } //create the menuuu====================== @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { // TODO Auto-generated method stub super.onCreateContextMenu(menu, v, menuInfo); MenuInflater inflater=getMenuInflater(); inflater.inflate(R.layout.contextmenu, menu); } //click to each menu====================== @Override public boolean onContextItemSelected(MenuItem item) { // TODO Auto-generated method stub if(item.getItemId()==R.id.item1) ...