AIDE Tutorial - 48 PopUp Menu
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">
<Button
android:onClick="popup"
android:text="PopUp"
android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
android:onClick="popup"
android:text="PopUp"
android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
Java
package com.kcgroup.popup;
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.widget.PopupMenu.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.widget.PopupMenu.*;
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void popup(View v){
PopupMenu pop=new PopupMenu (this,v);
MenuInflater mi=pop.getMenuInflater();
mi.inflate(R.menu.popup, pop.getMenu());
pop.show();
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void popup(View v){
PopupMenu pop=new PopupMenu (this,v);
MenuInflater mi=pop.getMenuInflater();
mi.inflate(R.menu.popup, pop.getMenu());
pop.show();
pop.setOnMenuItemClickListener(new OnMenuItemClickListener(){
@Override
public boolean onMenuItemClick(MenuItem aaa)
{ if(aaa.getItemId()==R.id.call){ Toast.makeText(getApplicationContext(),"Call is clicked",Toast.LENGTH_SHORT).show();}
if(aaa.getItemId()==R.id.sms){ Toast.makeText(getApplicationContext(),"SMS is clicked",Toast.LENGTH_SHORT).show();}
if(aaa.getItemId()==R.id.video){ Toast.makeText(getApplicationContext(),"Video Call is clicked",Toast.LENGTH_SHORT).show();}
// TODO: Implement this method
return true; }});}}
Create a new folder and add pop.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/call"
android:title="Call"/>
<item
android:id="@+id/sms"
android:title="SMS"/>
<item
android:id="@+id/video"
android:title="Video Call"/>
</menu>
public boolean onMenuItemClick(MenuItem aaa)
{ if(aaa.getItemId()==R.id.call){ Toast.makeText(getApplicationContext(),"Call is clicked",Toast.LENGTH_SHORT).show();}
if(aaa.getItemId()==R.id.sms){ Toast.makeText(getApplicationContext(),"SMS is clicked",Toast.LENGTH_SHORT).show();}
if(aaa.getItemId()==R.id.video){ Toast.makeText(getApplicationContext(),"Video Call is clicked",Toast.LENGTH_SHORT).show();}
// TODO: Implement this method
return true; }});}}
Create a new folder and add pop.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/call"
android:title="Call"/>
<item
android:id="@+id/sms"
android:title="SMS"/>
<item
android:id="@+id/video"
android:title="Video Call"/>
</menu>
nice
ReplyDelete