我在ToolBar中有购物车图标。当我单击购物车图标时,我编写了代码以导航到下一个活动。但点击不起作用。这是我的代码。请帮我解决。
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
badgeLayout = (RelativeLayout) menu.findItem(R.id.badge).getActionView(); /*-------Cart Basket with Counter---------*/
mCounter = (TextView) badgeLayout.findViewById(R.id.counter);
CommonUtil.dbUtil.open();
MainFragmentAdapter.CART_COUNT = String.valueOf(CommonUtil.dbUtil.getCartItem().getCount());
MainActivity.mCounter.setText(MainFragmentAdapter.CART_COUNT);
invalidateOptionsMenu();
badgeLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Config.menuItemClicked = true;
SharedPreferences.Editor editor = CommonUtil.pref.edit();
editor.putBoolean("cart_Clicked", Config.menuItemClicked);
editor.apply();
Intent next = new Intent(context, ProductActivity.class);
startActivity(next);
}
});
return super.onCreateOptionsMenu(menu);
}
答案 0 :(得分:0)
试过这个:
row['column_name']
答案 1 :(得分:0)
将代码更改为;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
badgeLayout = (RelativeLayout) menu.findItem(R.id.badge).getActionView(); /*-------Cart Basket with Counter---------*/
//instead of the above code try
View badgeLayoutView=MenuItemCompat.getActionView(menu.findItem(R.id.badge));
mCounter = (TextView) badgeLayout.findViewById(R.id.counter);
CommonUtil.dbUtil.open();
MainFragmentAdapter.CART_COUNT =String.valueOf(CommonUtil.dbUtil.getCartItem().getCount());
MainActivity.mCounter.setText(MainFragmentAdapter.CART_COUNT);
invalidateOptionsMenu();
//set the onClick listener to badgeLayoutView
badgeLayoutView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Config.menuItemClicked = true;
SharedPreferences.Editor editor = CommonUtil.pref.edit();
editor.putBoolean("cart_Clicked", Config.menuItemClicked);
editor.apply();
Intent next = new Intent(context, ProductActivity.class);
startActivity(next);
}
});
return super.onCreateOptionsMenu(menu);
}
确保您在菜单XML文件中大致设置了操作视图。您已使用app:actionLayout
<item
android:title="Badge"
android:id="@+id/badge"
app:actionLayout="@layout/your_action_layout"
app:showAsAction="ifRoom"/>
答案 2 :(得分:0)
请检查是否正在使用工具栏下面的滚动条。
如果您使用的是ScrollView,它将使全屏可滚动
在行下使用
Connect-PnPOnline –Url 'https://sharepoint.com/myurl' –Credentials $userCredential -ReturnConnection
Add-PnPListItem -List "POC_VRA" -ContentType "Item" -Values @{"Title"="Test Title"}
Disconnect-PnPOnline
在ScrollView内部
android:layout_marginTop="?android:attr/actionBarSize"
尝试
答案 3 :(得分:-1)
通过在XML中定义android:clickable="true"
,确保可以点击布局。