In this Below example you can set button click event and on long press button event.
Use can set two different event on button.
Use can set two different event on button.
- on button click
- on button long click.
see below code for this.
public class MainActivity extends Activity { /** Called when the activity is first created. */ private Button btn; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn = (Button) findViewById(R.id.button1); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Toast.makeText(MainActivity.this,"Button click", Toast.LENGTH_SHORT).show(); } }); btn.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { // TODO Auto-generated method stub Toast.makeText(MainActivity.this,"Button long click", Toast.LENGTH_SHORT).show(); return true; } }); } }
No comments:
Post a Comment