我已经创建了ButtonFragment类,我们在其中实现了 按钮单击视图上的方法并标识特定按钮,何时 我们点击按钮事件会起作用,但是当我们尝试打开时 像startActivity方法这样的另一个活动给出了错误。我们怎么能这样做 ,谁能帮我。以下是我的代码。
package com.viewpagerex;
import android.content.Context; import android.content.Intent;
import android.os.Bundle; import android.support.v4.app.Fragment;
import android.util.Log; import android.view.LayoutInflater; import
android.view.View; import android.view.View.OnClickListener; import
android.view.ViewGroup; import android.widget.ImageButton;
public class ButtonFragment extends Fragment implements OnClickListener
{
private static final String TAG = null;
protected static final Context context=null;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Log.e(TAG,"HelloHelooooo");
}
public void onActivityCreated(Bundle savedInstanceState)
{ super.onActivityCreated(savedInstanceState);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.button, container, false);
ImageButton imgBtn = (ImageButton) view.findViewById(R.id.imgButton);
imgBtn.setOnClickListener(this);
return view;
}
public void onClick(View v)
{
if(v.getId()==R.id.imgButton)
{
// TODO Auto-generated method stub
startActivity(new Intent(ButtonFragment.this,Activity_One.class));
Log.e(TAG,"Data show");
}
}
答案 0 :(得分:1)
你可以尝试:
startActivity(new Intent(v.getContext(),Activity_One.class));
并确保您已在Activity_One
AndroidManifest.xml