2013-03-31

【Android】長按圖片的事件處理

 
...
...

ImageView imgAlarm;
 
@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
  
    imgAlarm = (ImageView) findViewById(R.id.imgAlarm);
    imgAlarm.setLongClickable(true);
    imgAlarm.setOnLongClickListener(new View.OnLongClickListener() 
                                   {
                                        @Override
                                        public boolean onLongClick(View v) 
                                        {
                                             Toast.makeText(MainActivity.this, "長按下呼救鈕", Toast.LENGTH_LONG).show();
                                             return true;
                                        }
                                   });
    imgAlarm.setOnClickListener(new View.OnClickListener() 
                               {
                                    @Override
                                    public void onClick(View v) 
                                    {
                                         Toast.makeText(MainActivity.this, "short click 呼救鈕", Toast.LENGTH_LONG).show();
                                    }
                               });
}
 


沒有留言:

張貼留言