当前位置:网站首页>ContextMenu (context menu)
ContextMenu (context menu)
2022-07-27 19:52:00 【Ashurol】
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ShowListView();
}
/*
* * Show ListView
*/
private void ShowListView()
{
// Remember to add in the main layout file LIstView Control
ListView listview=(ListView) findViewById(R.id.listview);
ArrayAdapter<String> adp=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, getString());
listview.setAdapter(adp);
this.registerForContextMenu(listview);
}
/*
* Create the list item string collection required by the list adapter
*/
private ArrayList<String> getString()
{
ArrayList<String> list=new ArrayList<String>();
for(int i=0;i<5;i++)
{
list.add(" menu "+i);
}
return list;
}
/*
* Context menu content adding method
*/
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
menu.setHeaderTitle(" Context ");
menu.setHeaderIcon(R.drawable.ic_launcher);
// adopt Menu Add menu items to the layout file in
MenuInflater inflater=getMenuInflater();
inflater.inflate(R.menu.main, menu);
// Dynamically add menu items
// menu.add(1, 1, 1, " Copy ");
// menu.add(1, 2, 1, " Sticking ");
// menu.add(1, 3, 1, " shear ");
// menu.add(1, 4, 1, " rename ");
super.onCreateContextMenu(menu, v, menuInfo);
}
/*
* Add menu option click event
*/
@Override
public boolean onContextItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch(item.getItemId())
{
// Click to judge because there are two ways to add menu items , So there are two ID Judge
// case 1:
// Toast.makeText(this, " Click Copy ", Toast.LENGTH_SHORT).show();
// break;
// case 2:
// Toast.makeText(this, " Click Paste ", Toast.LENGTH_SHORT).show();
// break;
// case 3:
// Toast.makeText(this, " Click cut ", Toast.LENGTH_SHORT).show();
// break;
// case 4:
// Toast.makeText(this, " Click rename ", Toast.LENGTH_SHORT).show();
// break;
case R.id.action_settings1:
Toast.makeText(this, " Click Copy ", Toast.LENGTH_SHORT).show();
break;
case R.id.action_settings2:
Toast.makeText(this, " Click Paste ", Toast.LENGTH_SHORT).show();
break;
case R.id.action_settings3:
Toast.makeText(this, " Click cut ", Toast.LENGTH_SHORT).show();
break;
case R.id.action_settings4:
Toast.makeText(this, " Click rename ", Toast.LENGTH_SHORT).show();
break;
}
return super.onContextItemSelected(item);
}
}
//menu In a folder main file <pre name="code" class="html"><menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.xin.sxw.MainActivity" >
<item
android:id="@+id/action_settings1"
android:orderInCategory="100"
android:title=" Copy "
app:showAsAction="never"/>
<item
android:id="@+id/action_settings2"
android:orderInCategory="100"
android:title=" Sticking "
app:showAsAction="never"/>
<item
android:id="@+id/action_settings3"
android:orderInCategory="100"
android:title=" shear "
app:showAsAction="never"/>
<item
android:id="@+id/action_settings4"
android:orderInCategory="100"
android:title=" rename "
app:showAsAction="never"/>
</menu>
边栏推荐
- Application pool has been disabled
- IDEA:解决代码没有提示问题
- Turn Hyper-V on and off
- [Huawei cloud stack] [shelf presence] issue 13: have you seen the decoupling architecture of the management area? Help government and enterprise customers solve big problems
- Matplotlib(基本用法)
- [RCTF2015]EasySQL-1|SQL注入
- 【深度学习基础知识 - 46】贝叶斯定理与条件概率公式
- [basic knowledge of deep learning - 39] comparison of BN, LN and WN
- Pytorch reports CUDA error: no kernel image is available for execution on the device error
- VS2017#include 'xxx.h'
猜你喜欢

二叉搜索树

【深度学习基础知识 - 42】逻辑回归详解

四大组件之ContentProvider

Application pool has been disabled

A lock faster than read-write lock. Don't get to know it quickly

Detailed interpretation of IEC104 protocol (I) protocol structure

High cost, difficult to implement, slow to take effect, what about open source security?

Flink 算子简介

GestureDetector(手势识别)

MarqueeTextview(跑马灯)
随机推荐
Combinatorics -- permutation and combination
GestureOverlayView(手势识别2)
Flink简介以及运行架构
[basic knowledge of deep learning - 41] quick start learning materials for deep learning
JS 寻找所有节点sibling childNodes children
Transaction log full problem handling in sqlserver 2008
Application pool has been disabled
OPPO发布首款AR眼镜,宣布未来3年投入500亿进行研发
Session攻击
[basic knowledge of in-depth learning - 40] Why does CNN have more advantages than DNN in the field of images
【深度学习基础知识 - 39】BN、LN、WN的比较
A low code development platform that brings high-value user experience
Embedded C language structure
坚持软硬一体化,一恒科发力智能化教育机器人市场
Turn Hyper-V on and off
BroadcastReceiver(广播)
[deep learning target detection series - 01] what is target detection
一种比读写锁更快的锁,还不赶紧认识一下
FileOutputStream(文件储存)与FileInputStream(文件读取)
IEC104 规约详细解读(一) 协议结构