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 7824293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:33:05+00:00 2026-06-02T08:33:05+00:00

I want to make a compound control that is a EditText with a clear

  • 0

I want to make a compound control that is a EditText with a clear button. Since the main functionality will be the EditText functionality, I want it to be declarable in layout xmls with all the attributes of an EditText. But, it is actually going to be a LinearLayout with an EditText and an ImageButton in it.

Also, I want it to be used just like an EditText in the code, so I can just drop it in as a replacement.

I have this layout so far:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="@android:drawable/editbox_background" >
    <EditText 
        android:id="@+id/editText"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_gravity="center_vertical"
        android:background="#FFF" />
    <ImageButton
        android:id="@+id/clear"
        android:src="@drawable/clear_text"
        android:background="#FFF"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical" />
</LinearLayout>

But I am unsure how to proceed. How do I define a control that extends EditText if I need it to be a LinearLayout in order to use this layout? Or is my only option to draw the x manually in onDraw() and handle clicks myself?

  • 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-02T08:33:07+00:00Added an answer on June 2, 2026 at 8:33 am

    You can declare an custom view class which extends from LinearLayout like your XML. then load the Xml and add it to your custom view.

    If you want use it in the XML, you should first declare your own XML attribute by attrs.xml like below

    <declare-styleable name="CustomEditText">
        <attr name="text" format="string" />
    </declare-styleable>
    

    Then override the constructor with Attributes attrs and parse the attrs like below code

    TypedArray a = context.obtainStyledAttributes(attrs,R.styleable.CustomEditText);
    CharSequence s = a.getString(R.styleable.CustomEditText_text);
    setText(s.toString());
    

    Use it in the XML just like this:

    xmlns:anything="http://schemas.android.com/apk/res/yourpackagename" // for declare your namespace
    <yourpackagename
            android:background="@drawable/blue"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            anything:text="hi"/>
    

    To use it like the editText in the code, just wrap the custom view class.

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

Sidebar

Related Questions

I want make a alert that after click on button delete ask did you
I want to make a function called debug that outputs some info about objects.
I want make sql query which will insert values from one table to another
I want to make a compound query into MySQL. If the first part of
I understand that with MongoDB, for a query to make use of a compound
I want make a xslt transformation to xsl-fo but I´m not really sure that
i want make function like that function(data){ } i want this data as this
I want make a page (HTML + CSS) that fits all the space left
I want make a UI that is semi transparent in WPF VS2008, so I
I want to make a table that simply has two integer columns to serve

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.