Android devs!
1) I have tried to compare a string-array declared in my string.xml (I don't know if it's possible):
<string-array name="menu_array">
<item>Pizzas</item>
<item>Baguetes</item>
<item>Calzones</item>
<item>Esfihas</item>
<item>Refrigerantes</item>
<item>Vinhos</item>
<item>Cervejas</item>
</string-array>
2) I have a layout with an ImageView, to update images corresponding to each menu item string-array:
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:gravity="center"
android:clickable="true"
android:onClick="selecionarOpcao"
android:padding="32dp" />
3)I am using a navigation drawer. This is a class with a Fragment to show an image of item called:
public static class MenuFragment extends Fragment {
public static final String ARG_PRODUTOS_NUMBER = "produtos_number";
public MenuFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View rootView =
inflater.inflate(R.layout.fragment_menu, container, false);
int i = getArguments().getInt(ARG_PRODUTOS_NUMBER);
String menu = getResources().getStringArray(R.array.menu_array)[i];
int imageId = getResources().getIdentifier(
menu.toLowerCase(Locale.getDefault()), "drawable",
getActivity().getPackageName());
((ImageView) rootView.findViewById(R.id.image))
.setImageResource(imageId);
getActivity().setTitle(menu);
return rootView;
}
}
4) I would like to call different Intents according to the item clicked, the image loaded... I have trying this form, but not succesfully.
public void selecionarOpcao(View view)
{
switch (view.getId()) {
case R.id.image:
String[] produto =
getResources().getStringArray(R.array.menu_array);
if (produto.toString().equals("pizza")) {
startActivity(new Intent(this, ListarActivity.class));
} //Others Condictions
break;
}
}
As I compare these strings? Thanks guys!
replace with
UPDATE: You can try set tag with string
And use this tag in listener: