i am using page view in android and i view in this page viewer an images.
so i want to make event for on click. however, i call the image from another class like root view and i want the response of event from main class openoptionmenu() so i is there any way to call the event from second class when click the image?

my code for mainactivity

public class ScreenSlideActivity extends FragmentActivity  {



    public static String Pac_name="";
    public static boolean me_r=false;

    private ViewPager mPager;


    private PagerAdapter mPagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_screen_slide);

        Pac_name=getApplicationContext().getPackageName();
        // Instantiate a ViewPager and a PagerAdapter.
        mPager = (ViewPager) findViewById(R.id.pager);
        mPagerAdapter = new ScreenSlidePagerAdapter(getFragmentManager());
        mPager.setAdapter(mPagerAdapter);

        cu_sura=StoreManager.getCurrentSora(ScreenSlideActivity.this);
        if(cu_sura == 0)
        {
            mPager.setCurrentItem(604);
        }
        else
        {
            mPager.setCurrentItem(cu_sura);
        }

        mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                // When changing pages, reset the action bar actions since they are dependent
                // on which page is currently active. An alternative approach is to have each
                // fragment expose actions itself (rather than the activity exposing actions),
                // but for simplicity, the activity provides the actions in this sample.

                invalidateOptionsMenu();

            }
        });

        mPager.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View arg0, MotionEvent arg1) {
                // TODO Auto-generated method stub
                openOptionsMenu();
                return false;

            }
        });

       +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    }



in the place of ++++++ i want to call event of onclick for image in the second class





    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // Inflate the layout containing a title and body text.
        ViewGroup rootView = (ViewGroup) inflater
                .inflate(R.layout.fragment_screen_slide_page, container, false);


        ScreenSlideActivity.cu_sura=mPageNumber;
        int num=(mPageNumber -605)*-1;
        String name="p"+num;

        int imgId = getResources().getIdentifier(name, "drawable",com.bilal.read_quran.ScreenSlideActivity.Pac_name );
      //    Bitmap b = BitmapFactory.decodeResource(getResources(), imgId);
        ((ImageView) rootView.findViewById(R.id.imageView1)).setImageResource(imgId);
        ((ImageView) rootView.findViewById(R.id.imageView1)).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                final Handler mHandler = new Handler();

            }
        });
        // Set the title view to show the page number.
      /*  ((TextView) rootView.findViewById(android.R.id.text1)).setText(
                getString(R.string.title_template_step, mPageNumber + 1));
*/
        return rootView;
    }
  • Create custom listener
  • Register listener with component to receive update info
  • Call listener on touch and pass data to be received by listeneing component
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.