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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:50:23+00:00 2026-06-06T20:50:23+00:00

Im searching this since yesterday. I’ve got on many Activities some piece of code

  • 0

Im searching this since yesterday. I’ve got on many Activities some piece of code which displays user name and login. I dont want to copy and paste code in layout into every Activity, but I want something just like user controls in .NET. I’ve read a lot of topic about custom controls but or I don’t understand it or its not possible do to this (I dont belive in that option)

  • 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-06T20:50:24+00:00Added an answer on June 6, 2026 at 8:50 pm

    Yes it is possible. Look at this sample. It is a custom Numeric Keyboard or a custom View or a custom user control. Customize it and create your own user control:

    import java.util.ArrayList;
    
    import org.mabna.order.R;
    
    import android.app.Activity;
    import android.content.Context;
    import android.text.InputType;
    import android.util.AttributeSet;
    import android.view.LayoutInflater;
    import android.view.MotionEvent;
    import android.view.View;
    import android.view.View.OnTouchListener;
    import android.view.ViewGroup;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.ImageButton;
    import android.widget.LinearLayout;
    
    // this NumericKeyboard works only for EditTexts which 
    // have a tag with "usesNumericKeyboard" key and value of "true"
    // use tag with "ignoreMeForNumericKeyboardTouchListener" key and 
    // value "true" for controls you do not want to set its touchListener 
    public class NumericKeyboard extends LinearLayout implements OnTouchListener {
    
        private View mainView = null;
        private EditText currentEditText;
        private Button btn0;
        private Button btn1;
        private Button btn2;
        private Button btn3;
        private Button btn4;
        private Button btn5;
        private Button btn6;
        private Button btn7;
        private Button btn8;
        private Button btn9;
        private ImageButton btnBackSpace;
        private ImageButton btnDeleteAll;
    
        public NumericKeyboard(Context context) {
            super(context);
        }
    
        public NumericKeyboard(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        protected void initialize() {
            LayoutInflater layoutInflater = (LayoutInflater) getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View view = layoutInflater
                    .inflate(R.layout.view_numeric_keyboard, this);
    
            btn0 = (Button) view.findViewById(R.id.btn0);
            btn1 = (Button) view.findViewById(R.id.btn1);
            btn2 = (Button) view.findViewById(R.id.btn2);
            btn3 = (Button) view.findViewById(R.id.btn3);
            btn4 = (Button) view.findViewById(R.id.btn4);
            btn5 = (Button) view.findViewById(R.id.btn5);
            btn6 = (Button) view.findViewById(R.id.btn6);
            btn7 = (Button) view.findViewById(R.id.btn7);
            btn8 = (Button) view.findViewById(R.id.btn8);
            btn9 = (Button) view.findViewById(R.id.btn9);
            btnBackSpace = (ImageButton) view.findViewById(R.id.btnBackSpace);
            btnDeleteAll = (ImageButton) view.findViewById(R.id.btnDeleteAll);
    
            btn0.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    editCurrentText(v, "0");
                }
            });
            btn1.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    editCurrentText(v, "1");
                }
            });
            btn2.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    editCurrentText(v, "2");
                }
            });
            btn3.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    editCurrentText(v, "3");
                }
            });
            btn4.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    editCurrentText(v, "4");
                }
            });
            btn5.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    editCurrentText(v, "5");
                }
            });
            btn6.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    editCurrentText(v, "6");
                }
            });
            btn7.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    editCurrentText(v, "7");
                }
            });
            btn8.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    editCurrentText(v, "8");
                }
            });
            btn9.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    editCurrentText(v, "9");
                }
            });
            btnBackSpace.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    editCurrentText(v, "<");
                }
            });
            btnDeleteAll.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    editCurrentText(v, "D");
                }
            });
    
            if (mainView == null && !this.isInEditMode()) {
                setTouchListenerForChildViews();
                this.setVisibility(GONE);
            }
        }
    
        protected void editCurrentText(View v, String character) {
            if (currentEditText != null) {
                if (character.compareTo("<") == 0) {
                    String text = currentEditText.getText().toString();
                    if (text.length() == 0) {
                    } else if (text.length() == 1) {
                        currentEditText.setText("");
                    } else {
                        text = text.substring(0, text.length() - 1);
                        currentEditText.setText(text);
                    }
                } else if (character.compareTo("D") == 0) {
                    currentEditText.setText("");
                } else {
                    String text = currentEditText.getText().toString();
                    text += character;
                    currentEditText.setText(text);
                }
            }
        }
    
        // @Override
        // protected void onLayout(boolean changed, int l, int t, int r, int b) {
        //
        // super.onLayout(changed, l, t, r, b);
        // }
    
        public void setTouchListenerForChildViews() {
            final Activity act = (Activity) getContext();
            mainView = act.getWindow().getDecorView()
                    .findViewById(android.R.id.content);
    
            if (mainView == null)
                return;
    
            ArrayList<View> queue = new ArrayList<View>();
            queue.add((View) mainView);
    
            while (!queue.isEmpty()) {
                View v = queue.remove(0);
                if (v instanceof EditText && v.getTag(R.id.usesNumericKeyboard) == Boolean
                        .valueOf(true)) {
                    ((EditText) v).setInputType(InputType.TYPE_NULL);
                    ((EditText) v).setCursorVisible(true);
                    v.setOnFocusChangeListener(new OnFocusChangeListener() {
                        @Override
                        public void onFocusChange(View v, boolean hasFocus) {
                            if (hasFocus)
                            {
                                for (NumericKeyboard numericKeyboard : arrNumericKeyboard) {
                                    numericKeyboard.currentEditText = (EditText) v;
                                    numericKeyboard.setVisibility(View.VISIBLE);
                                }
                            }
                        }
                    });
                }
    
                if (v instanceof NumericKeyboard) {
                } else {
                    if (v.getTag(R.id.ignoreMeForNumericKeyboardTouchListener) != Boolean
                            .valueOf(true)) {
                        v.setOnTouchListener(this);
                    }
                    if (v instanceof ViewGroup) {
                        ViewGroup vg = (ViewGroup) v;
                        for (int i = 0; i < vg.getChildCount(); i++) {
                            View vChild = vg.getChildAt(i);
                            queue.add(vChild);
                        }
                    }
                }
            }
        }
    
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (v instanceof EditText && v.getTag(R.id.usesNumericKeyboard) == Boolean
                    .valueOf(true)) {
                for (NumericKeyboard numericKeyboard : arrNumericKeyboard) {
                    numericKeyboard.currentEditText = (EditText) v;
                    numericKeyboard.setVisibility(View.VISIBLE);
                }
            } else {
                for (NumericKeyboard numericKeyboard : arrNumericKeyboard) {
                    numericKeyboard.setVisibility(View.GONE);
                }
            }
            return false;
        }
    
        static ArrayList<NumericKeyboard> arrNumericKeyboard =
                new ArrayList<NumericKeyboard>();
    
        public static void registerNumericKeyboard(
                NumericKeyboard numericKeyboard) {
    
            numericKeyboard.initialize();
    
            arrNumericKeyboard.add(numericKeyboard);
        }
    
        public static void unregisterNumericKeyboard(
                NumericKeyboard numericKeyboard) {
            arrNumericKeyboard.remove(numericKeyboard);
        }
    
        public static void showForEditText(EditText editText)
        {
            for (NumericKeyboard numericKeyboard : arrNumericKeyboard) {
                numericKeyboard.setVisibility(View.VISIBLE);
                numericKeyboard.currentEditText = editText;
            }
        }
    
        public static void hide()
        {
            for (NumericKeyboard numericKeyboard : arrNumericKeyboard) {
                numericKeyboard.setVisibility(View.GONE);
            }
        }
    }
    

    its layout as view_numeric_keyboard.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/background06"
        android:orientation="vertical" >
    
        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
    
            <Button
                android:id="@+id/btn7"
                android:layout_width="50dip"
                android:layout_height="50dip"
                android:text="7" >
            </Button>
    
            <Button
                android:id="@+id/btn8"
                android:layout_width="50dip"
                android:layout_height="50dip"
                android:text="8" >
            </Button>
    
            <Button
                android:id="@+id/btn9"
                android:layout_width="50dip"
                android:layout_height="50dip"
                android:text="9" >
            </Button>
        </LinearLayout>
    
        <LinearLayout
            android:id="@+id/linearLayout2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
    
            <Button
                android:id="@+id/btn4"
                android:layout_width="50dip"
                android:layout_height="50dip"
                android:text="4" >
            </Button>
    
            <Button
                android:id="@+id/btn5"
                android:layout_width="50dip"
                android:layout_height="50dip"
                android:text="5" >
            </Button>
    
            <Button
                android:id="@+id/btn6"
                android:layout_width="50dip"
                android:layout_height="50dip"
                android:text="6" >
            </Button>
        </LinearLayout>
    
        <LinearLayout
            android:id="@+id/linearLayout3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
    
            <Button
                android:id="@+id/btn1"
                android:layout_width="50dip"
                android:layout_height="50dip"
                android:text="1" >
            </Button>
    
            <Button
                android:id="@+id/btn2"
                android:layout_width="50dip"
                android:layout_height="50dip"
                android:text="2" >
            </Button>
    
            <Button
                android:id="@+id/btn3"
                android:layout_width="50dip"
                android:layout_height="50dip"
                android:text="3" >
            </Button>
        </LinearLayout>
    
        <LinearLayout
            android:id="@+id/linearLayout4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
    
            <ImageButton
                android:id="@+id/btnBackSpace"
                android:layout_width="50dip"
                android:layout_height="50dip"
                android:scaleType="fitCenter"
                android:src="@drawable/backspace"
                android:text="-" />
    
            <Button
                android:id="@+id/btn0"
                android:layout_width="50dip"
                android:layout_height="50dip"
                android:text="0" />
    
            <ImageButton
                android:id="@+id/btnDeleteAll"
                android:layout_width="50dip"
                android:layout_height="50dip"
                android:scaleType="fitCenter"
                android:src="@drawable/remove02"
                android:text="-" />
    
        </LinearLayout>
    
    </LinearLayout>
    

    using it in your Activity layout:

    <org.mabna.order.ui.NumericKeyboard
                            android:id="@+id/numericKeyboard1"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content" >
                        </org.mabna.order.ui.NumericKeyboard>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been searching for some good guidance on this since the concept was introduced
I have been searching this since yesterday and still nothing. From all that researching
I've been searching for this for some time, but I couldn't seem to find
I need a VBA code which can do some action in VBA when the
I have been searching a solution for this since 2 days but couldn't find
I need to extract the virtual host name of a HTTP request. Since this
I am searching this and googling out since quite a few days now, but
I'm searching about this since last week, almost all links about DriveLetter x DevicePath/Volume/Device
I'm searching for this for quite some time now. I saw few similar questions
Ok. I have searching on this site Since August 24 2011.(not that it matters)

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.