0

I have an activity (MainActivity.java) in which content view is like this

this.setContentView(R.layout.standalone_example);

my standalone_example.xml is like this

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
<com.abc.view.PageCurlView
    android:id="@+id/dcgpagecurlPageCurlView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:background="@drawable/page1" />
</RelativeLayout>

I am done some work in PageCurlView.java now I want to access objects and variables of PageCurlView.java in my MainActivity.java, I am searching for hours but couldnt find any answer, any suggestions thanks in advance.

Muaz Usmani
  • 1,298
  • 6
  • 26
  • 48

1 Answers1

1

You can get a reference to the inflated PageCurlView using findViewById() in your activity. In a method in your activity:

PageCurlView mPageCurlView = (PageCurlView) findViewById(R.id.dcgpagecurlPageCurlView1);

You can then call methods or access public variables on mPageCurlView. Please note that setContentView() must be called first in your activity before you can use findViewById().

Flynn81
  • 4,108
  • 29
  • 28
  • So after setContentView use findViewById and you can start calling methods on the PageCurlView object. Did this answer your question? – Flynn81 Jun 24 '12 at 13:54