0

so i am trying to do this tutorial http://code.tutsplus.com/tutorials/android-sdk-creating-custom-views--mobile-14548 to create a custom view button so that i can make the pink circle thats drawn on the screen i am getting an error when i try to do the tutorial here is the main file.

public class Main extends ActionBarActivity {
    Draw v;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        LinearLayout layout1 = new LinearLayout (this);
        FrameLayout game = new FrameLayout(this);
        Draw v = new Draw (this, null);

        game.addView(v);
        game.addView(layout1);
        setContentView(game);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

here is the XML file for that this is where im getting the error

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:custom="http://schemas.android.com/apk/res/com.Tripps.test.Draw"
    xmlns:Tripps="http://schemas.android.com/apk/res/com.Tripps.test"
    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.Tripps.test.Main" >

   <com.Tripps.test.Draw
    android:id="@+id/custView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_margin="5dp"
    custom:circleColor="#ff0099"
    custom:circleLabel="Hello"
    custom:labelColor="#ffff66" 
    </com.Tripps.test.Draw>

</RelativeLayout>

here is the Draw class that extends viewc this is what i am trying to reference

public class Draw extends View {


    //circle and text colors
    private int circleCol, labelCol;
    //label text
    private String circleText;
    //paint for drawing custom view
    private Paint circlePaint;


    public Draw(Context context, AttributeSet attrs){
        super(context, attrs);
      //paint object for drawing in onDraw
        circlePaint = new Paint();
      //get the attributes specified in attrs.xml using the name we included
        TypedArray a = context.getTheme().obtainStyledAttributes(attrs,
            R.styleable.DrawV, 0, 0);
    }
       @Override
       protected void onDraw(Canvas canvas) {;

       }
}

and here is what the tutorial told me to do its a file called attr in the values folder. in the i dont know why but i put it there

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="Draw">
    <attr name="circleColor" format="color" ></attr>
    <attr name="circleLabel" format="string"></attr>
    <attr name="labelColor" format="color"></attr>
</declare-styleable>
</resources>

1 Answer 1

1

tutorial told me to do its a file called attr in the values folder. in the i dont know why but i put it there

To use custom attributes for custom view, add all attributes in attrs.xml file.

Create attrs.xml file inside res/values folder.

Sign up to request clarification or add additional context in comments.

1 Comment

there is now an error saying "no resource identifier found for the attribute 'circleColor' in package com.Tripp.Draw

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.