Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3283878
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:05:29+00:00 2026-05-17T20:05:29+00:00

I am new to android .can any one solve the following problem? I just

  • 0

I am new to android .can any one solve the following problem?
I just create the class like below .I need to know how to set property for the Edit text field

public class CustomEditText extends EditText{

public CustomEditText(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
}

}

Note: I mean the property like this
Edittext.setText(“Demo”);
Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:05:30+00:00Added an answer on May 17, 2026 at 8:05 pm

    So there are a couple ways this can be interpreted and I will try to cover all of them.

    EditText has multiple constructors. The one you have overridden requires that you as the developer set the properties in code for the rest of this instances usage. So you can actually just call setText(someString) from within this class or since the method is public call it directly on an instance of your class.

    If you override the constructor that contains an attributeSet,

     EditText(Context, AttributeSet)
    

    You can use your component as part of an xml layout and set attributes on it there as if it were another EditText (as long as you call super(context, attributeSet). If you want to define your own custom attributes on top of that then that’s actually quite neat how you do this.

    In your project hierarchy, from the root you should either have or need to create a folder called “res/values” Within that folder a file named attr.xml should be created.

    <declare-styleable name="myCustomComponents">
    <!-- Our Custom variable, optionally we can specify that it is of integer type -->
    <attr name="myCustomAttribute" format="integer"/>
    ...
    <!-- as many as you want -->
    </declare-styleable>
    

    Now within your new constructor that makes use of the AttributeSet, you can read this new attribute, “myCustomAttribute”.

    public CustomEditText(Context context, AttributeSet set) {
        super(context, set);
        // This parses the attributeSet and filters out to the stuff we care about
        TypedArray typedArray = context.obtainStyledAttributes(R.stylable.myCustomComponents);
        // Now we read let's say an int into our custom member variable.
        int attr = typedArray.getInt(R.styleable.myCustomComponents_myCustomAttribute, 0);
        // Make a public mutator so that others can set this attribute programatically
        setCustomAttribute(attr);
        // Remember to recycle the TypedArray (saved memory)
        typedArray.recycle();
    }
    

    Now that we have declared our new attribute and have setup code to read it, we can actually use it programatically or in an XML layout. So let’s say you have an Xml layout in file, layout.xml

    <ViewGroup 
       xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:custom="http://schemas.android.com/apk/res/com.my.apk.package"
    >
    
    ...
    
    <com.my.full.apk.package.CustomEditText
       android:id="@+id/custom_edit"
       ...
       custom:myCustomAttribute="12"
    />
    ...
    </ViewGroup>
    

    So in this we create a layout like normal, but notice we declare a new xml namespace. This is for your new component and your apk. So in this case “custom” is being used it will look inside your defined stylables for new parameters. By doing the previous steps with attr.xml, you have declared “myCustomAttribute” as a component attribute off of the http://schemas.android.com/apk/res/com.my.apk.package namespace. After that it’s up to you to decide what attributes you would like to expose and what those attributes actually mean. Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way I can load a class based on what version of
What I did was create two .java files. One that can compile and run
New class is a subclass of the original object It needs to be php4
New to silverlight. Traditionally if I were to design a wizard-like process where a
New to WCF, but familiar with COM+ - can I wrap a WCF service
I am a new comer in Android development, I have downloaded and installed the
i am trying to run google map tutorial using following link http://mobiforge.com/developing/story/using-google-maps-android followed all
I am using following code to open Android Contacts @Override public void onCreate(Bundle savedInstanceState)
I am a new android developer and I am currently making an application to
new to Android. Checked the FAQs on the SDK site but didn't find anything

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.