有一些复杂性......我该如何解决
我Dynamacally添加选项菜单
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
menu.clear();
for (int i = 0; i < SplashActivity.arraylistsSports.size(); i++) {
lists.add(SplashActivity.arraylistsSports.get(i));
arryList.add(SplashActivity.arraylistsSportsURL.get(i));
menu.add(i, i, i, SplashActivity.arraylistsSports.get(i));
// menu.add(groupId, itemId, order, title)
}
return super.onCreateOptionsMenu(menu);
}
如何获得onOptionsItemSelected(MenuItem item)
ItemId
意味着获得ID&#34; ItemSelected&#34;并执行操作
基本上我添加或解析XML格式的数据并保存所需的数据onCreateOptionsMenu(Menu menu)
我想打开在&#34; arrayList&#34;中添加的网址arryList.add(SplashActivity.arraylistsSportsURL.get(i));
------------------------------------------------- < / p>
![Perfoem Operation On Option Menu ItemId Click "ItemId in Order loke Idexes" :)]
onOptionsItemSelected(MenuItem item)
我们如何获得身份
@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch (item.getItemId()) {
// case R.id.menu_settings:
// break;
}
return true;
}
答案 0 :(得分:0)
这个Artical对我有用....查看以下网址(链接)
http://www.yogeshblogspot.com/android-creating-option-menu-programmatically/
在我的情况下,如果我查找XML项目,则表示长度大于当前项目
然后使用Respectable XML Iten Lenth更新Apk版本等于ArrayList lenght equal。
或者Chek the Maximum cases
case MENU_ITEM1:
break;
比你的可能性更重要:)
如果您有任何Idia PLZ分享......: - )
编辑回答:
在我的案例中我添加
menu.add(i, i, i, SplashActivity.arraylistsSports.get(i));
// menu.add(groupId, itemId, order, title)
For循环中的itemId意味着i = 0,1,2,3,4,5 ....等等
@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch (item.getItemId()) {
case 0:
URL = SplashActivity.arraylistsSportsURL.get(0);
GetLiveTvToken();
break;
case 1:
URL = SplashActivity.arraylistsSportsURL.get(1);
GetLiveTvToken();
break;
case 2:
URL = SplashActivity.arraylistsSportsURL.get(2);
GetLiveTvToken();
break;
case 3:
URL = SplashActivity.arraylistsSportsURL.get(3);
GetLiveTvToken();
break;
.
.
.
.
.
.
.
.
.
.
.
.
.
and So On till 500 Items :-)
}
}