Draw View from XML file under other TextView - android

I'm trying to draw a Canvas in a View and show this View under some TextViews I defined in my XML file.
Everytime I test the App it just doesn't start on the device.
However, the parts themself work:
When I change the setContentView(R.layout.activity_main); in the onCreate() to setContetView(new CustomView(this)); it works, but of course without the textView.
My activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="#+id/sampleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some Text"/>
<com.example.simon.drawtest.CustomView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/sampleText"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
My MainActivity.java:
package com.example.simon.drawtest;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
My CustomView.java:
package com.example.simon.drawtest;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
public class CustomView extends View {
private Paint paint;
public CustomView(Context context) {
super(context);
paint = new Paint();
paint.setColor(Color.GRAY);
}
#Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.BLUE);
canvas.drawCircle(200, 200, 100, paint);
}
}

show your whole activity_main.xml...
both Views should be wrapped in e.g. FrameLayout
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/sampleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some Text"/>
<com.example.simon.drawtest.CustomView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/sampleText"
android:layout_alignParentBottom="true"/>
</FrameLayout>
edit: ok, so you have RelativeLayout.. also note that with Android 5.0 elevation attribute was introduced and you may have some problems with drawing order like HERE
also... your TextView is first in XML so it will be drawn before your custom view (drawing by order if elevation isn't set)
also... android:layout_below="#+id/sampleText" below means under in vertical axis. try to remove this line
edit: user post exception stack trace in comments, so below I'm pasting proper answer for his case (comment copied):
your error stack says
Caused by: java.lang.NoSuchMethodException:
[class android.content.Context, interface
android.util.AttributeSet]
you have only one constructor with Context
only, system needs also one with additional AttributeSet. check out
THIS question & answer, apply proper constructors for your CustomView

Related

How do I draw 2D primtives to a SurfaceView that's a submember of my layout?

I'm just learning Android and Java. I'm familiar with graphics and programming in general in other languages.
I have a simple layout with some buttons, text views, and a SurfaceView all inside a RelativeLayout like this:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Quit"
android:id="#+id/buttonShutdown"
android:layout_below="#+id/textView2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:onClick="shutdown"/>
<SurfaceView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/surfaceView"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/buttonShutdown"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
Then I have a simple MainActivity.java which is like this:
public class MainActivity extends AppCompatActivity
{
SurfaceView surfaceView;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
surfaceView = (SurfaceView) findViewById(R.id.surfaceView);
holder = surfaceView.getHolder();
holder.getSurface();
}
protected void shutdown(View view)
{
System.exit(0);
}
}
Obviously there's a little more to my code because I have a couple buttons and a couple textviews, but the point is I have a layout with several widgets and the SurfaceView is just one of them.
I've seen a number of examples of drawing to a surface view but they all seem to take over the whole screen and stuff.
How can I simply draw 2D lines and stuff to my SurfaceView as is without obliterating the rest of my code or layout widgets?
I've been working for days on this and it has never taken me this much effort in any other language/framework to simply draw some 2D lines!
I would be most grateful for any working examples that work with my existing layout.
UPDATE:
To clarify, the problem I'm having trouble with is how to get a handle on the surfaceView in order to get a handler in order to get a canvas on it. Once I get a canvas interface then I can lock, draw, and unlock. But I cannot figure out how to get the Canvas attached to the surfaceView.
UPDATE:
I think I have a holder for the surface view now, but how do I Get the canvas for it?
Thank you very much,
Jesse
Okay after much hair pulling I got it working.
Now please a note to you grownups out there: this is intended to be a very very simple educational demonstration of the minimal code to draw lines on the screen in a Surface View. I also know that holder.getSurface(); takes some time to come alive and so drawing cannot happen right away. That's why it's in an onClick. I also know that SurfaceView rendering should be done from its own thread, and that it should be set up with 3 callbacks.
This is just a simple sample so please do not flame me for not writing the ideal fully fledged app! Thank you kindly.
My MainActivity.java:
package com.gladeworks.gwscope ;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity
{
TextView textView = null;
SurfaceView surfaceView;
SurfaceHolder holder;
Canvas canvas;
Paint paint;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.textView);
textView.setText("Press the Draw button!");
surfaceView = (SurfaceView) findViewById(R.id.surfaceView);
holder = surfaceView.getHolder();
holder.getSurface();
paint = new Paint();
final Button buttonDraw = (Button) findViewById(R.id.buttonDraw);
buttonDraw.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
draw(view);
}
});
}
protected void draw(View view) //This gets called when the Draw button is clicked.
{
paint.setColor(Color.GREEN);
paint.setStrokeWidth(5);
canvas = holder.lockCanvas();
if (canvas == null) {
textView.setText("Canvas is still null");
} else {
canvas.drawRGB(32, 32, 255); //Clear the canvas to light blue
canvas.drawLine(0,0,1000,1000,paint);//Draw a line from top left corner down and right.
holder.unlockCanvasAndPost(canvas);
textView.setText("Done drawing!");
}
}
}
And here's my activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.gladeworks.gwscope.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Uninitialized"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignBottom="#+id/buttonExit"
android:layout_toLeftOf="#+id/buttonExit"
android:layout_toStartOf="#+id/buttonExit"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Quit"
android:id="#+id/buttonExit"
android:layout_alignTop="#+id/buttonDraw"
android:layout_toLeftOf="#+id/buttonDraw"
android:layout_toStartOf="#+id/buttonDraw"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Draw"
android:id="#+id/buttonDraw"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
<SurfaceView
android:id="#+id/surfaceView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/buttonExit"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
</RelativeLayout>
Things to improve:
The line drawing code should really be in its own thread so it doesn't block the user interface thread.
The labels for buttons and stuff should really be defined int he resources file for easier translation efforts.
The canvas and SurfaceView shuold be set up with callbacks for dealing with Creation, Change, and Destruction.
But this should provide a clear path to beginners for understanding the needed sequence of steps to draw line graphics to a SurfaceView.

Simple custom control - Force closed

I have created an android project using eclipse.the default system generated code looked as below
package com.rmycustomclass.bengler;
import android.app.Activity;
import android.os.Bundle;
public class RMyCustomClassActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
I wanted to try a simple custom control , so i changed the code as below. when i searched the web to create a simple custom control there are mentioned like "create class by subclassing a View". so tried as below by modifying the code.but it was not running and always force closed.
package com.rmycustomclass.bengler;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
public class RMyCustomClassActivity extends View {
private Paint myPaint;
public RMyCustomClassActivity(Context cxt, AttributeSet attribute){
super(cxt,attribute);
init();
}
public RMyCustomClassActivity(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
init();
}
public void init(){
myPaint = new Paint();
myPaint.setTextSize(12);
myPaint.setColor(0xFF668800);
myPaint.setStyle(Paint.Style.FILL);
}
#Override
protected void onDraw(Canvas canvas) {
canvas.drawText("TEEEST", 100, 100, myPaint);
}
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
this.setMeasuredDimension(150,200);
}
}
Below is my xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:orientation="vertical">
<TextView
android:id="#+id/textView1"
android:text="Enter text"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tableLayout1">
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1">
</Button>
<Button android:layout_width="wrap_content" android:id="#+id/button1" android:layout_height="40dip" android:text="My button" android:layout_weight="1"></Button>
<test.control
android:id="#+id/control"
android:layout_height="match_parent"> </test.control>
</TableLayout>
</LinearLayout>
When you create a project in eclipse it links your activity (RMyCustomClassActivity in your case) as the launcher in Android manifest...But since you have changed the activity to a View
android runtime cannot find the activity to launch...See your manifest file and you will find your class as the launcher activity
add android:layout_width="match_parent"
<test.control
android:id="#+id/control"
android:layout_height="match_parent"
android:layout_width="match_parent"
>

Orientation change does not redraw layout completely

This is a Major Edit on my previous question
I'm creating a custom (composite) component named OneLineSeeker that consists of a TextView and a SeekBar.
When I have multiple OneLineSeekers declared in a layout, they don't retain their state on configuration change. All seeker thumbs assume the same position (the position of the last OneLineSeeker) on configuration change.
If I don't use the custom component and use only SeekBars individually (uncomment //a() in main activity), they will retain their individual positions on configuration change.
Can anyone help?
src files
A_seekbarsActivity.java
package com.an;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SeekBar;
public class A_seekbarsActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//a();
}
void a() {
setContentView(R.layout.main_1);
Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
SeekBar sb = (SeekBar) findViewById(R.id.seekBar1);
if(sb.getProgress() > 50) sb.setProgress(0);
else sb.incrementProgressBy(5);
}
});
}
}
OneLineSeeker.java
package com.an;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
public class OneLineSeeker extends LinearLayout {
public OneLineSeeker(Context context, AttributeSet attrs) {
super(context, attrs);
View ols = LayoutInflater.from(context).inflate(R.layout.one_line_seeker, this, true);
TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.OneLineSeeker, 0, 0);
String text = array.getString(R.styleable.OneLineSeeker_name);
if (text != null)
((TextView) ols.findViewById(R.id.name)).setText(text);
array.recycle();
}
}
res/layout files
main_1.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<SeekBar android:id="#+id/seekBar1" android:layout_height="wrap_content" android:layout_width="match_parent"></SeekBar>
<SeekBar android:id="#+id/seekBar2" android:layout_height="wrap_content" android:layout_width="match_parent"></SeekBar>
<SeekBar android:id="#+id/seekBar3" android:layout_height="wrap_content" android:layout_width="match_parent"></SeekBar>
<Button android:text="Button" android:id="#+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:oneLineSeeker="http://schemas.android.com/apk/res/com.an"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.an.OneLineSeeker
android:id="#+id/s1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
oneLineSeeker:name="1"
/>
<com.an.OneLineSeeker
android:id="#+id/s2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
oneLineSeeker:name="2"
/>
<com.an.OneLineSeeker
android:id="#+id/s3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
oneLineSeeker:name='3'
/>
</LinearLayout>
one_line_seeker.xml
<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id='#+id/name'
android:text='name'
/>
<SeekBar
android:id='#+id/seekbar'
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</merge>
res/values files
attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="OneLineSeeker">
<attr name="name" format="string"/>
</declare-styleable>
</resources>
Its not supposed to reset its position to zero. This is actually a feature. When view has id associated with, it usually saves and the restores its state on configuration changes.
If you don't want specific view to save state on configuration change, you can remove android:id from view's entry in layout (but you won't be able to control that view then). Another alternative is to extend ProgressBar and disable its ability to restore state.
The last one option is the easiest one: override onRestoreInstanceState() and reset state there:
#Override
protected void onRestoreInstanceState(Bundle savedInstanceState)
{
super.onRestoreInstanceState(savedInstanceState);
bar.setProgress(0);
}
But I would strongly recommend not resetting view state. After all the whole idea of restoring state on configuration change is to make user think as if nothing really changed. And you need to have very strong reasons to disable this behavior.
In that u have to define Orientation Change Methods.....
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
onCreate(null);
}
Try this Code may u get any Help.....

How to draw on an ImageView

Why will this code not draw a circle where the user touches in an imageview and output the coordinates to a textview?
package com.smallbore.smallbore;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.ImageView;
import android.widget.TextView;
public class targetenter extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.targetenter);
}
public class ImageView1 extends ImageView {
public int x;
public int y;
public ImageView1(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public boolean dispatchtouchevent(MotionEvent event){
x = (int) event.getX();
y = (int) event.getY();
TextView t1 = (TextView)findViewById(R.id.textView2);
t1.setText("x="+x);
TextView t2 = (TextView)findViewById(R.id.textView3);
t2.setText("y="+y);
invalidate();
return true;
}
#Override
public void onDraw(Canvas canvas){
super.onDraw(canvas);
canvas.drawCircle(x,y,10, null );
}
}
}
and the xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:id="#+id/linearLayout1" android:layout_height="fill_parent" android:layout_width="fill_parent">
<TextView android:layout_height="wrap_content" android:text="#string/cposition" android:id="#+id/textView1" android:layout_width="wrap_content"></TextView>
<com.smallbore.smallbore.targetenter.Imageview1 android:id="#+id/imageView1" android:layout_width="300dip" android:layout_height="300dip" android:background="#drawable/target" android:layout_gravity="center_horizontal"></com.smallbore.smallbore.targetenter.Imageview1>
<TextView android:text="TextView" android:id="#+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<TextView android:text="TextView" android:id="#+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</LinearLayout>
Change onTouchEvent to dispatchTouchEvent. Also, make sure that you are using imageView1 in your XML, and not just ImageView.
You are not calling invalidate() in your onTouchEvent. When ever you change something on a canvas it must be redrawn. fyi, if you are not on UI thread you must call postinvalidate(). refer to this api demo to learn more about dealing with drawing on canvas. http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/FingerPaint.html
I'm not sure that Cristian's suggestion of using dispatchTouchEvent() is a good one, that method makes sense in ViewGroup descendants to dispatch touch events to its children. Yet his recommendation of using the custom view in xml layout declaration is important. You do that like:
<package.that.contains.targetenter.imageView1 android:id ....
that is, you need to specify the full package to your custom ImageView class (btw, in Java there's the convention of using capital letter for class names: imageView1 -> ImageView1). You simply have to use it were you were using ImageView, and I think you will have to make it public or better declare it in another file.
To have your onDraw() method called, you'll need to call invalidate() as Veeresh suggests, so that your imageView1 will redraw. But you have to call its super, or you will only get the circles drawn:
#Override
public void onDraw(Canvas canvas){
super.onDraw(canvas);
canvas.drawCircle(x,y,10, null );
}
If you're still having problems it might be useful to see your targetenter.xml layout.

Drawing on a screen with other views in android

I have been searching for the past few hours to the answer to a very dumb question. I know how to draw on the canvas in android if you extend the view class, modify onDraw and set setContentView() to a new instance of that class. However, I need to also have 2 TextViews and 2 EditTexts at the bottom of the activity and if setContentView() is set to only have that view, these views will, obviously, not display. How can put all of these on the screen?
EDIT: Here is my code: (the package name is android.physicsengine)
package android.physicsengine;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
import android.widget.RelativeLayout;
public class ResultantForceEngine extends Activity {
private EditText mag;
private EditText dir;
private View image;
private RelativeLayout layout;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.resultant_force);
mag = (EditText)findViewById(R.id.magnitude);
dir = (EditText)findViewById(R.id.direction);
}
public class MyView extends View{
public MyView(Context context){
super(context);
}
public MyView(Context context, AttributeSet attrs){
super(context, attrs);
}
public MyView(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle);
}
#Override
protected void onDraw(Canvas canvas){
canvas.drawColor(Color.BLACK);
Paint circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
circlePaint.setColor(Color.RED);
canvas.drawLine(canvas.getWidth()/2, canvas.getHeight()/2-200, canvas.getWidth()/2 ,canvas.getHeight()/2+200, circlePaint);
canvas.drawLine(canvas.getWidth()/2-200, canvas.getHeight()/2, canvas.getWidth()/2+200 ,canvas.getHeight()/2, circlePaint);
}
}
}
and the xml
<view class="android.physicsengine.ResultantForceEngine$MyView"
android:id="#+id/image"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<TextView android:id="#+id/magText"
android:text="Magnitude (N) ="
android:textSize="15dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:gravity="center_vertical"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true" />
<EditText android:id="#+id/magnitude"
android:inputType="numberDecimal"
android:layout_alignParentBottom="true"
android:layout_toRightOf ="#id/magText"
android:layout_width="wrap_content"
android:padding="3dip"
android:layout_height="wrap_content" />
<TextView android:id="#+id/dirText"
android:text="Angle (deg) ="
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dip"
android:layout_alignParentBottom="true"
android:layout_toRightOf ="#id/magnitude"
android:padding="3dip"
android:gravity="center_vertical" />
<EditText android:id="#+id/direction"
android:inputType="numberDecimal"
android:layout_alignParentBottom="true"
android:layout_toRightOf ="#id/dirText"
android:layout_alignParentRight="true"
android:layout_height="wrap_content"
android:padding="3dip"
android:layout_width="wrap_content"/>
Basically you need to define your XML file with your custom view class and the other widgets you have. In your case, there would be the custom view, 2 textviews and 2 edittexts in the XML file.
You define the custom view in XML just like any other widget, except you use the namespace of the view and the class name.
<com.example.android.myCustomView
android:id="#+id/my_custom_view"
...
Then inside your activity a simple call
setContentView(R.layout.main);
Edit: The problem is your class is private, so it "isn't seen" when your activity makes a call the layout and tries to inflate it.
Edit2: Of course this won't work, you're using an inner class! You have to communicate stuff like this if you expect to get answers.
The XML syntax for an inner class is different.
<view class="com.example.android.MyClass$MyInnerClass"
You should be able to use the class that you extended in your res/layout/main.xml just like you would any other View class, and add your TextView and EditTexts in the layout .xml file like normal. I have not personally done this, but I have used custom View classes in this way.
Then for your setContentView you would just use the layout .xml file like:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
...

Categories

Resources