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

  • Home
  • SEARCH
  • 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 7853949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:51:56+00:00 2026-06-02T19:51:56+00:00

I have a CompositeComponent (EditText+ImageButton) When clicking on button the edittext content will be

  • 0

I have a CompositeComponent (EditText+ImageButton)
When clicking on button the edittext content will be cleared.
It is working fine. My problem is setting attributes to my component. I am using declare-styleable to set attributes to my component.

I am successful at setting minLines, maxLines and textColor.

How can I set inputtype to my component via xml.

my attributes.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="CET">
        <attr name="MaxLines" format="integer"/>
        <attr name="MinLines" format="integer"/>
        <attr name="TextColor" format="color"/>
        <attr name="InputType" format="integer" />
        <attr name="Hint" format="string" />
    </declare-styleable>
</resources>

And usage of mycomponent in main_layout.xml:

<com.test.ui.ClearableEditText
        xmlns:cet="http://schemas.android.com/apk/res/com.test.ui"
        android:id="@+id/clearableEditText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        cet:MaxLines="2"
        cet:MinLines="1"
        cet:TextColor="#0000FF"
        cet:InputType="" <---I cant set this property--------->
        cet:Hint="Clearable EditText Hint">

    </com.test.ui.ClearableEditText>

Ordinary Edittext usage:

<EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="numberSigned" <--------I want to use this property--------> >

I cant use ENUM in my attribute.xml.
How to refer android:inputType="numberSigned" in my cet:InputType?

EDIT:

This is how I assign properties in my ClearableEditText.java

TypedArray a = getContext().obtainStyledAttributes(attrs,R.styleable.CET,0, 0);

            int minLines = a.getInt(R.styleable.CET_MinLines, 1);
            int maxLines = a.getInt(R.styleable.CET_MaxLines, 100);
            String hint = a.getString(R.styleable.CET_Hint);
            int textColor = a.getColor(R.styleable.CET_TextColor, Color.BLACK);
            int inputType = a.getInt(R.styleable.CET_InputType, -108);

            Log.i(TAG, "ClearableEditText: Min Line "+minLines +" Max Lines: "+maxLines+" Hint "+hint+" Color: "+textColor+" Input Type: "+inputType);

            edit_text.setMaxLines(maxLines);
            edit_text.setMinLines(minLines);
            edit_text.setTextColor(textColor);
            edit_text.setHint(hint);
            if(inputType != -108)
                edit_text.setInputType(inputType);

You can see there is no problem with assigning the inputType property to editText.

  • 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-06-02T19:51:58+00:00Added an answer on June 2, 2026 at 7:51 pm

    Lets say you have a custom view named InputView, which is not a TextView (lets say its a RelativeLayout).

    In your attrs.xml:

    <declare-styleable name="InputView">
    
        <!-- any custom attributes -->
        <attr name="title" format="string" /> 
    
        <!-- standart attributes, note android: prefix and no format attribute -->
        <attr name="android:imeOptions"/> 
        <attr name="android:inputType"/>
    
    </declare-styleable>
    

    In an xml layout where you want to include InputView:

    <!-- note xmlns:custom and com.mycompany.myapp -->
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:custom="http://schemas.android.com/apk/res-auto"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
            <!-- note that you will be using android: prefix for standart attributes, and not custom: prefix -->
            <!-- also note that you can use standart values: actionNext or textEmailAddress -->
            <com.mycompany.myapp.InputView
            android:id="@+id/emailField"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            custom:title="@string/my_title"
            android:imeOptions="actionNext|flagNoExtractUi"
            android:inputType="textEmailAddress" />
    
    </FrameLayout>
    

    Inside your custom class you can extract attributes as usual:

        ...
    
        private String title;
        private int inputType;
        private int imeOptions;
    
        ...
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.InputView);
    
        int n = a.getIndexCount();
        for (int i = 0; i < n; i++) {
            int attr = a.getIndex(i);
            switch (attr) {
            case R.styleable.InputView_title:
                title = a.getString(attr);
                break;
            //note that you are accessing standart attributes using your attrs identifier
            case R.styleable.InputView_android_inputType:
                inputType = a.getInt(attr, EditorInfo.TYPE_TEXT_VARIATION_NORMAL);
                break;
            case R.styleable.InputView_android_imeOptions:
                imeOptions = a.getInt(attr, 0);
                break;
            default:
                Log.d("TAG", "Unknown attribute for " + getClass().toString() + ": " + attr);
                break;
            }
        }
    
        a.recycle();
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with my composite component in JSF2. I implement a list
I'm creating a composite component in JSF 2..., inside it I have defined a
**Have it working now. I forgot to populate the Array List. How embarrassing. I'm
i have a composite component that contains a form with ajax. what i can't
I have a simple composite component with an optional ajax listener implemented with the
I have a simple JSF 2.0 composite component example. <!DOCTYPE html PUBLIC -//W3C//DTD XHTML
I have a composite component (collapsiblePanel). The component uses the collapsible bean to provide
I have a JSF 2 composite component that employs some Ajax behavior. I want
Have a problem that seems easy on paper but i'm having a big problem
I have the following Java Server Faces 2.0 composite component. Notice i am using

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.