【问题标题】:though i am using classname.this still getting "The constructor Intent(MySampleFragment, Class<Alert>) is undefined" error虽然我正在使用 classname.this 仍然得到“构造函数 Intent(MySampleFragment,Class<Alert>)未定义”错误
【发布时间】:2014-03-04 23:34:55
【问题描述】:

这是我收到错误的代码部分。

    @Override
    public void onClick(View v)
    {
                  Intent i = new Intent(MySampleFragment.this,Alert.class);
                  startActivity(i);
    }

【问题讨论】:

    标签: android android-intent android-2.2-froyo


    【解决方案1】:

    使用getActivity()v.getContext() 而不是MySampleFragment.this 作为 Intent 构造函数的第一个参数:

    Intent i = new Intent(getActivity(),Alert.class);
    //Intent i = new Intent(v.getContext(),Alert.class);
    startActivity(i);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-05
      • 1970-01-01
      • 2018-07-13
      • 1970-01-01
      • 1970-01-01
      • 2011-11-22
      相关资源
      最近更新 更多