0

嘿,我在这里查看导航栏示例: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;
    }
4

2 回答 2

0

is this what you want?

        Intent intent = new Intent();
        intent.setClass(LauncherActivity.this, OtherActivity.class);
        startActivity(intent);
于 2013-08-16T10:45:49.680 回答
0
ImageView image = (ImageView) view.findViewById(R.id.fav);

image.setOnClickListener(new View.OnClickListener(){

    @Override
    public void onClick(View v){
        Intent intent = new Intent(getActivity(), TargetActivity.class);
        intent.putExtra("customTag", someTag);
        startActivity(intent);
    }
});   

you can replace getActivity() with CurrentActivity.this in most cases.

edit: am i getting closer?

于 2013-08-16T10:47:00.080 回答