嘿,我在这里查看导航栏示例:http: //developer.android.com/training/implementing-navigation/nav-drawer.html
在该示例中,列表是通过字符串加载的。然后将数组用作名称来识别“可绘制”中的图像。我想知道如何更改代码以启动新活动而不是显示图像。
以下是该网站的相应代码部分:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_planet, container, false);
int i = getArguments().getInt(ARG_PLANET_NUMBER);
String planet = getResources().getStringArray(R.array.planets_array)[i];
int imageId = getResources().getIdentifier(planet.toLowerCase(Locale.getDefault()),
"drawable", getActivity().getPackageName());
((ImageView) rootView.findViewById(R.id.image)).setImageResource(imageId);
getActivity().setTitle(planet);
return rootView;
}