Build error: Cannot find symbol. Points to navigation actions - android

I keep getting an error that says that it cannot find the navigation actions. Here is the place that it gives me errors:
public void onItemClick(String item) {
switch (card) {
case ACCESSORIES:
navController.navigate(TypeOfInfoFragmentDirections.actionTypeOfInfoToAccessories(item));
case ARMOR_PIECES:
navController.navigate(TypeOfInfoFragmentDirections.actionTypeOfInfoToArmorPieceType(item));
case ARMOR_SETS:
navController.navigate(TypeOfInfoFragmentDirections.actionTypeOfInfoToArmorSets(item));
case DESTINIES:
navController.navigate(TypeOfInfoFragmentDirections.actionTypeOfInfoToDestinyList(item));
case ENEMIES:
navController.navigate(TypeOfInfoFragmentDirections.actionTypeOfInfoToEnemyList(item));
case GEMS:
navController.navigate(TypeOfInfoFragmentDirections.actionTypeOfInfoToGemList(item));
case LORESTONES:
navController.navigate(TypeOfInfoFragmentDirections.actionTypeOfInfoToLoreSets(item));
case POTIONS:
navController.navigate(TypeOfInfoFragmentDirections.actionTypeOfInfoToPotionTypes(item));
case QUESTS:
navController.navigate(TypeOfInfoFragmentDirections.actionTypeOfInfoToQuestList(item));
case SKILLBOOKS:
navController.navigate(TypeOfInfoFragmentDirections.actionTypeOfInfoToSkillbook(item));
case TRAINERS:
navController.navigate(TypeOfInfoFragmentDirections.actionTypeOfInfoToTrainerList(item));
case TWISTS:
navController.navigate(TypeOfInfoFragmentDirections.actionTypeOfInfoToTwistList(item));
case WEAPONS:
navController.navigate(TypeOfInfoFragmentDirections.actionTypeOfInfoToWeaponList(item));
It gives me errors on all 13 navigation actions. Here is my gradle: https://pastebin.com/jaK6CK7z
And finally here is the navigation file: https://pastebin.com/8DyR7vpj
As far as I can tell, I have all the elements needed. Any help is greatly appreciated.

I figured out the problem. I was trying to navigate to destinations that were in a nested NavGraph. I found that I did not need to have nested graphs, so taking out the graphs and leaving the fragments was all I needed to do.

Related

How to create Inbox like floating action button in Android with Speed dial animation

I want to create a floating action button that will animate to show inner speed dial buttons like Inbox android app developed by Google.
Example:
I found the expected output by using Floating Action Button Speed Dial library.
The library is available on Jcenter so no additonal repository is required.
Step 1: Add the following dependency
implementation "com.leinardi.android:speed-dial:2.0.0"
Step 2: Add the SpeedDialView to your layout:
<com.leinardi.android.speeddial.SpeedDialView
android:id="#+id/speedDial"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
app:sdMainFabClosedSrc="#drawable/ic_add_white_24dp" />
Step 3: Add the items to the SpeedDialView:
SpeedDialView speedDialView = findViewById(R.id.speedDial);
speedDialView.addActionItem(
new SpeedDialActionItem.Builder(R.id.fab_link, R.drawable.ic_link_white_24dp)
.create());
Step 4: Add the click listeners:
speedDialView.setOnActionSelectedListener(new SpeedDialView.OnActionSelectedListener() {
#Override
public boolean onActionSelected(SpeedDialActionItem speedDialActionItem) {
switch (speedDialActionItem.getId()) {
case R.id.fab_link:
showToast("Link action clicked!");
return false; // true to keep the Speed Dial open
default:
return false;
}
}
});
Source: https://github.com/leinardi/FloatingActionButtonSpeedDial
The FloatingActionButtonSpeedDial is the best library i have found that suits your requirements.
It's quite flexible and you can find that the repository's Main Sample implementing a lot of possible use cases such as add/remove button from the floating menu, change the color of labels and button background etc.
The only drawback I've found in the meantime is that you have to add your buttons programmatically and not in the xml layout file.
Anyway, the first answer is good but he missed a small detail. When you create a button to add to your SpeedDialView:
speedDialView.addActionItem(
new SpeedDialActionItem.Builder(R.id.fab_link, R.drawable.ic_link_white_24dp)
.create());
The R.id.fab_link is the id of the new ActionItem (floating button) so you can reference it afterwards in the onClickListener of the speedDialView:
speedDialView.setOnActionSelectedListener(new SpeedDialView.OnActionSelectedListener() {
#Override
public boolean onActionSelected(SpeedDialActionItem actionItem) {
switch (actionItem.getId()) {
case R.id.fab_add:
// do something
break;
case R.id.fab_link:
// do something else
break;
}
return true; // To keep the Speed Dial open
}
});
It's just an #IdRes, an integer that is expected to be an id resource reference.
So you can do like they did in the official sample here, and create a resource file containing items with type id.
I hope you find this answer helpful.

onClick() does not work after appying dexguard. Is there any way to solve this?

i am using dexguard to secure my app. Recently i updated the dexgaurd version
from 8.0.1 to 8.2.15. Earlier everything is working fine before the update. But with the version 8.2.15 when i apply dexguard, onCick method does not works in one of fragment SettingsFragment, for all of the other Fragments it works fine. However the code and method of implementing onClick() is same for all Fragments. But for SettingsFragment it's not working. Please help.
Here is my onClick method in SettingsFragment
View.OnClickListener onClickListener = new View.OnClickListener() {
#Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.relSignOut:
mCallback.doSignOut();
break;
// case R.id.relEditProfile:
// loadManageProfile();
// break;
case R.id.btn_edit_profile:
loadManageProfile();
break;
case R.id.relDynamicFxRate:
parent.startSetExchangeAlertActivity();
break;
}
}
};
Thanks in Advance
You should exclude obfuscation of onClick methods like this:
-keepclassmembers class * {
public void onClick (android.view.View);
}
(Converting my comment to answer)
Please kick off the switch statement and replace it with if-else. May seem bit unscientific and illogical, but I worked for me many times.
I don't know if it's a possible bug in the compiler or in Android or not, but sometimes rejecting switch statement only doesn't help. Then I've to replace view.getId() with view.getPosition() and check by order or something like this to make it work anyway.
From T.Neidhart's comment: The reason it fails is probably due to resource optimization which remaps resource IDs. Normally these remapped resource IDs get replaced everywhere in the code, but it might go wrong in case of switch statements. You can disable resource optimization like that: -optimizations resource/compaction –

Switch - case expressions must be constant expressions

I'm using ActionBarSherlock and then onOptionsItemSelected to start a new activity when a specific menu item has been clicked. The code worked properly before adding ABS, and now I get case expressions must be constant expressions error on case.
#Override
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item)
{
switch (item.getItemId()) {
case R.id.about: //error
startActivity(new Intent(this, AboutActivity.class));
break;
case R.id.feedback: //error
//launch activity
break;
default:
break;
return super.onOptionsItemSelected(item);
}
The same code worked fine before adding ActionBarSherlock.
I've replaced the switch/case statement with if/else. You can just click on switch and then press CTRL+1 if you're in Eclipse.
Posted as an answer as Sam adviced:
If you are in a library you have to change all the switch/case statements to if/else blocks from ADT version 14.
See:
tools.android.com/tips/non-constant-fields
To switch from the switch/case statement to if/for, simply use alt + enter in android studio.
Switch case missing closing "}".

how to creat a toggle button for widget app

this is the closet post I found to my question How to make a toggle button for a widget android, however, I am looking for a more straight forward solution to this.
Does any one have any straight forward solution to make a toggle button using image button to create a simple widget app?
I would greatly appreciate any advice on that.
I only need a simple toggle button which I can listen for the state change using a service class. Is this possible?
Many thanks in advance.
As per your comments, I am posting sample relevant code below which can be used to change the image used in your widget:
case WifiManager.WIFI_STATE_ENABLED:
remoteViews.setImageViewResource(R.id.widget_normal_imagebutton, R.drawable.ic_widget_wifitimer_on);
break;
case WifiManager.WIFI_STATE_ENABLING:
remoteViews.setImageViewResource(R.id.widget_normal_imagebutton, R.drawable.ic_widget_wifitimer_transition);
break;
case WifiManager.WIFI_STATE_DISABLED:
remoteViews.setImageViewResource(R.id.widget_normal_imagebutton, R.drawable.ic_widget_wifitimer_off);
break;
case WifiManager.WIFI_STATE_DISABLING:
remoteViews.setImageViewResource(R.id.widget_normal_imagebutton, R.drawable.ic_widget_wifitimer_transition);
break;
case WifiManager.WIFI_STATE_UNKNOWN:
remoteViews.setImageViewResource(R.id.widget_normal_imagebutton, R.drawable.ic_widget_wifitimer_error);
break;
For a more thorough tutorial about creating homescreen widgets, you can visit:
http://www.vogella.com/articles/AndroidWidgets/article.html
It explains the whole process including how to update the widget with new information

Android : alternative to setVisibility to Display images onscreen

First of all, I am very new at Android and teaching myself so I am not asking you to code it for me. Just give me some terms, topics or a subject to study and I will hit the books and figure it out.
I am making an app where the user sets what appears on screen by pressing a button or selecting an image. The only way I know how to do this is to have an onClickListener set a variable and use a switch statement to display an imageView that corresponds to the variable selected.
example:
//on click listeners set variable userPic1 and userPic2
switch(userPic1){
case 1:
pic11.setVisibility(View.VISIBLE);
pic12.setVisibility(View.GONE);
pic13.setVisibility(View.GONE);
pic14.setVisibility(View.GONE);
break;
case 2:
pic11.setVisibility(View.GONE);
pic12.setVisibility(View.VISIBLE);
pic13.setVisibility(View.GONE);
pic14.setVisibility(View.GONE);
break;
case 3:
pic11.setVisibility(View.GONE);
pic12.setVisibility(View.GONE);
pic13.setVisibility(View.VISIBLE);
pic14.setVisibility(View.GONE);
break;
case 4:
pic11.setVisibility(View.GONE);
pic12.setVisibility(View.GONE);
pic13.setVisibility(View.GONE);
pic14.setVisibility(View.VISIBLE);
break;
}
switch(userPic2){
case 1:
pic21.setVisibility(View.VISIBLE);
pic22.setVisibility(View.GONE);
pic23.setVisibility(View.GONE);
pic24.setVisibility(View.GONE);
break;
case 2:
pic21.setVisibility(View.GONE);
pic22.setVisibility(View.VISIBLE);
pic23.setVisibility(View.GONE);
pic24.setVisibility(View.GONE);
break;
case 3:
pic21.setVisibility(View.GONE);
pic22.setVisibility(View.GONE);
pic23.setVisibility(View.VISIBLE);
pic24.setVisibility(View.GONE);
break;
case 4:
pic21.setVisibility(View.GONE);
pic22.setVisibility(View.GONE);
pic23.setVisibility(View.GONE);
pic24.setVisibility(View.VISIBLE);
break;
}
}
I feel like there is probably a better way to code this, but the bigger problem is in my XML layouts. I have all of these imageViews stacked on top of each other and it is getting difficult to see how they will look because it's just a mess.
Any help is appreciated
http://developer.android.com/reference/android/widget/ViewFlipper.html will make this a bit easier for you to manage, without such unruly code.
Using the ViewFlipper as suggested may help if you're trying to switch between many views. However, if you're really just changing the image and don't need to change your layout instead of creating lots of views, I would simply just set the image on your ImageView (I'm assuming picXX are ImageViews). You can store your IDs in an array or two and get them from there. Something like:
int[] userPics1 = new int[] {R.drawable.pic1, R.drawable.pic2, ... }
and then:
ImageView pic = (ImageView)findViewById(R.id.pic);
pic.setImageResource(userPics1[userPic1]);

Categories

Resources