ad728

Sunday, December 10, 2017

AIDE Tutorial - 49 Context Menu on TextView

AIDE Tutorial - 49 Context Menu on TextView

Watch the Video Below



Main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">
    <TextView
android:id="@+id/mainTextView"
android:textSize="25dp"
 android:text="Long Press to see context menu"        android:layout_width="wrap_content"       android:layout_height="wrap_content" />
</LinearLayout>
MainActivity.java
package com.kcgroup.CM;


import android.app.*;
import android.os.*;
import android.widget.*;
import android.view.*;
import android.view.ContextMenu.*;
public class MainActivity extends Activity
{TextView text;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
text=(TextView)findViewById(R.id.mainTextView);
registerForContextMenu(text); }
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo)

{ // TODO: Implement this method
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Select Action");
menu.add(0,v.getId(),0,"Call");
menu.add(0,v.getId(),0,"SMS");
menu.add(0,v.getId(),0,"VideoCall");}
@Override
public boolean onContextItemSelected(MenuItem item)
{ if(item.getTitle()=="Call"){
Toast.makeText(this,"Call is Clicked",Toast.LENGTH_SHORT).show();} else
if(item.getTitle()=="SMS"){ Toast.makeText(this,"SMS is Clicked",Toast.LENGTH_SHORT).show(); } else
if(item.getTitle()=="VideoCall"){ Toast.makeText(this,"VideoCall is Clicked",Toast.LENGTH_SHORT).show();
} // TODO: Implement this method
return true;}}

Share:

0 comments:

Post a Comment

Total Pageviews

Sponsor

Sponsor

ad300

Blog Archive