onclickリスナーをフラグメントに追加しないでください。次に、インテントをブロードキャストします。
public class Your extends Fragment
{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View inflatedView = inflater.inflate(R.layout.customlayout, null);
inflatedView.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent temp = new Intent("anything.com.com.CHECK_CURRENT_PAGE_ITEM");
getActivity().sendBroadcast(temp);
}
});
}
}
次に、メインアクティビティでブロードキャストレシーバーを登録します
public class Youractivity extends FragmentActivity
{
private BroadcastReceiver clickedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Toast toast = Toast.makeText(getApplicationContext(),
pager.getCurrentItem(), Toast.LENGTH_SHORT);
}
};
@Override
public void onCreate()
{
...
registerBroadcstReceiver(clickedReceiver, new IntentFilter("anything.com.com.CHECK_CURRENT_PAGE_ITEM"))
...
}
@Override
public void onDestroy()
{
unregisterBroadcastReceiver()
}
}