在android carousel视图中,如何在点击android carousel查看图像时启动多个活动?

时间:2015-10-13 04:21:22

标签: android android-fragments android-activity

我的问题是,如何在点击android carousel查看图片时启动多项活动?

我试着编写下面给出的一些代码。但它只能一个一个地启动一个活动而不是一个活动,所以请仔细检查......

public class MyFragment extends Fragment {
public static Fragment newInstance(MainActivity context, int pos, float scale, boolean isBlured) {
  Bundle b = new Bundle();
  b.putInt("pos", pos);
  b.putFloat("scale", scale);

  return Fragment.instantiate(context, MyFragment.class.getName(), b);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
 /* if (container == null) {
    return null;
  }*/

  LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(400,400);
  LinearLayout fragmentLL  = (LinearLayout) inflater.inflate(R.layout.mf, container, false);
  int pos   = this.getArguments().getInt("pos");
  TextView tv  = (TextView) fragmentLL.findViewById(R.id.text);

  tv.setText("Image " + pos);

  ImageView iv = (ImageView) fragmentLL.findViewById(R.id.pagerImg);

  iv.setLayoutParams(layoutParams);
  iv.setImageResource(MainActivity.mainActivityCtx.coverUrl[pos]);
  iv.setPadding(15, 15, 15, 15);
  iv.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {

        /*Intent intent = new Intent(getActivity(),image1.class);
        startActivity(intent);*/
        int postion=0;
        switch (postion)
        {
          case 0:  Intent newActivity0 = new Intent(getActivity(), image1.class);
            startActivity(newActivity0);
            break;
          case 1:  Intent newActivity1 = new Intent(getActivity(), image2.class);
            startActivity(newActivity1);
            break;
          case 2:  Intent newActivity2 = new Intent(getActivity(), image3.class);
            startActivity(newActivity2);
            break;
          case 3:  Intent newActivity3 = new Intent(getActivity(), image4.class);
            startActivity(newActivity3);
            break;
          case 4:  Intent newActivity4 = new Intent(getActivity(), image5.class);
            startActivity(newActivity4);
            break;
        }
    }
  });


  // MyLinearLayout root = (MyLinearLayout) fragmentLL.findViewById(R.id.root);
  //float scale   = this.getArguments().getFloat("scale");
  //root.setScaleBoth(scale);

  return fragmentLL;
}
}

R.id.pagerImage是LinearLayout图像的id。

1 个答案:

答案 0 :(得分:0)

if (!pdata->empty()) { os << pdata->front(); std::for_each(std::next(pdata->begin()), pdata->end(), [&os](auto&& v){ os << ", " << v; }); }

添加final
int pos

final int pos = this.getArguments().getInt("pos"); 语句的变量switch更改为position

pos