在Fragment中,我创建了一个按钮单击处理程序,并使用Intent想要去Karta类,但是失败了。 Eclipse失败了 构造函数Intent(new View.OnClickListener(){},Class Karta)未定义 (hlkjbhlkbnkl / NK / N; KN; / NK; / NK; NK; n)的
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
public class Fragment1 extends Fragment {
Button button1;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment1,
container, false);
button1=(Button)rootView.findViewById(R.id.button1);
button1.setOnClickListener (new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent (this,Karta.class);
startActivity(intent);
}});
return rootView;
}
}
import android.app.Activity;
import android.os.Bundle;
public class Karta extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.karta);
}
}
答案 0 :(得分:2)
Intent intent = new Intent (Fragment1.this.getActivity(),Karta.class);