I have a problem. I’d like to use layout for designe this ArcTimerActivity.
When I change setContentView(cv) to setContentView(R.layout.arc_timer_activity) IT DOES NOT WORK. (I’m not programmer, so its not easy for me)
public class ArcTimerActivity extends Activity implements Runnable, View.OnClickListener, View.OnLongClickListener {
private ArcTimerView cv = null;
private Thread t = null;
private boolean run_thread = false;
private int run_thread_fps = 50; // Max 1000
private IntervalSession is;
private final int MENU_PREFERENCES = 15;
//@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
is = new IntervalSession();
restorePreferences();
cv = new ArcTimerView(this, is);
cv.setOnClickListener(this);
cv.setOnLongClickListener(this);
restoreRunningState(getLastNonConfigurationInstance());
setContentView(cv);
}
....................
IF USE setContentView(R.layout.arc_timer_activity) – NO ERRORS, JUST Black SCREEN. Maby I need smth to add or change to display Activity in layout?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<View
android:layout_width="fill_parent"
android:layout_height="fill_parent"
></View>
</LinearLayout>
First give a specific id to any layout let say View in your xml file where you want to add that cv (or IntervalSession()).
Now setContentView(R.layout.arc_timer_activity);
Now, define object of Resource View like below:
Now in Jva file give resources to that id
Now create object of the view you want to add.
and add that to your View.
This way you can add any view dynamically to your resource layout.
Feel free for any comments.
UPDATE
There is one of my project Demo in which i have implemented as like your requirement. See code snippet below. MyView is the call to whom i have added. Concentrate on it.
In above code, MyView is the class to whom i want to add in to the layout. Please refer that code and you will ge how i have add MyView class object in to the layout.
Hope this code help you.