import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.TextView;
import android.widget.Toast;
public class ContextMenuEx extends Activity {
/** Called when the activity is first created. */
TextView tv;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv=(TextView)findViewById(R.id.tv1);
registerForContextMenu(tv);
}
public void onCreateContextMenu(ContextMenu menu,View v,ContextMenuInfo m)
{
super.onCreateContextMenu(menu, v, m);
menu.add("Edit");
menu.add("Delete");
menu.add("Exit");
}
public boolean onContextItemSelected(MenuItem item)
{
if(item.getTitle()=="Edit")
{
Toast.makeText(this,item.getTitle(),Toast.LENGTH_LONG).show();
}
else if(item.getTitle()=="Delete")
{
Toast.makeText(this,item.getTitle(),Toast.LENGTH_LONG).show();
}
else if(item.getTitle()=="Exit")
{
Toast.makeText(this,item.getTitle(),Toast.LENGTH_LONG).show();
}
return super.onContextItemSelected(item);
}
}
No comments:
Post a Comment