I have to create a group of EditText s that each can contains 1 character of a pin code with auto flow between like in the following image -
when user tapping the the keyboard, the application moves to the next EditText with out any Intervention of the user.
How can it be done?
It's called PinView, here is a link for PinView.
They have made custom keyboard too. Including back button, and verification code, make changes as per your requirement. It's very good and simple tutorial to achieve this important functionality.
Make an array of edit text:
private EditText pinInput[] = new EditText[4];
Then add each EditText in array:
pinInput[0] = (EditText) findViewById(R.id.first);
...
Then implement the functionality by using onTextChanged and onFucusChanged listeners
Related
As shown in image, I have added the same fragment 5 times in activity by performing on click operation on ADD FRAGMENT button:
Now I want to get all user entered data from those 5 edittext on click of GET DATA button. Is this possible?
(Both buttons is in Main Activity)
First we need to traverse to the dynamic edit text linear layout and then only we can count how many edit texts are avaliable then read the values of corresponding edit text :)
//step:1
LinearLayout layout = (LinearLayout)findViewById(R.id.LinearDynamicEditTextID);// change as your //dynamic EditTexts' parent Linear Layout id.
//step:2
for(int i=0;i<layout.getChildCount();i++)// Count how many children avaliable
{
View v = (View)layout.getChildAt(i);// get the child view
if (v instanceof EditText)// verifying whether the child is EditText for secure.
{
EditText editText = (EditText)layout.getChildAt(i);//thats it.
Log.w("Edit Text "+i+" Value" , editText.getText());
}
}
Now I want to get all user entered data from those 5 edittext on click
of GET DATA button. Is this possible?
Answer: Yes, this is possible.
How?
Solution: You can make public variables in the activity and you can access those variables from the fragment which you are adding. On click of GET DATA button, you can read those variables set by the different fragment and show them in the same Activity or in different Fragment.
I am using Edit Text watcher, to do some calculations.like below,
And every Edit Text group (A,B,C) is working fine independently and relatively. But relatively worked only if i come from top to bottom. I want to refresh (getText and setText) on every Edit Text onTextChange() method invoked. i can do this using custom method .
But can i do this in one go , like all edit text values of a particular XML get refresh, so each editText onTextChange will be called in TOP-DOWN approach, Because every descendent group is dependent in some context to previous group .
This is doable, you just must have an algorithm. But yes, it is possible, and not too challenging...
As a hint, EditText.onTextChanged() methods inside of the each listener will need access its other 5 EditText siblings/neighbors. (A-C rows and 1-2 columns, respectively).
All 6 onTextChangedListener implementations for the 6 Edit Texts may need to be unique in how they handle textChanged events. You will need to pass in the objects in which they are responsible for changing in their constructors.
ie
EditText et1 = (EditText)findViewById(R.id.editText1);
EditText et2 = (EditText)findViewById(R.id.editText2);
et1.setOnTextChangedListener(new TextChangedListener(et2){
//global var
EditText nextEditText;
public TextChangedListener(EditText editText){
super();
nextEditText = editText;
}
public void onTextChanged(){
this.alert();
}
public void alert(){
//modify data here and update self if necessary.
//then alert the next boxes on text changed method.
nextEditText = editText.getListener().alert();
}
});
In my Application I want to Add and Remove View (like Button, or Textview, Checkbox ) by Coding (Programming ).
In Details:
I have One EditText and One Add Button. User Enter Anything in EditText and Press the Add Button then this one is added in bellow LinearLayout, and whether User click on his/her added Button it will going to next LinearLayout.
I get sucess upto this.
but when user click the button in second LinearLayout then it will come back on first Linearlayout. I am getting error Here, i don't know where I made a Mistake.
And I also facing Problem about how can I Store this all. Like User Add 5 Button and closed the application and whenever he/she came back to application I need whatever he/she previously added.
Here is what i done.
http://dynamicandroidview.blogspot.com/2011/12/how-to-add-view-in-android-by-coding.html
Try to create a database table with minimum 2 columns in your case it will be id and buttonText.
Now when user clicks on the add button it will save text to the database and will create the button dynamically below any buttons which are already created before or as a new button.
Now in your onCreate method get the count of text thats stored in database.Some thing like the following code:
DB getData = DB.getInstance();
getData.open(this);
ArrayList<TextHolder> getList = new ArrayList<TextHolder>();
getList = getData.getAllTextFromGeT();
getData.close();
x = genList.size();
Here x will be the number/count of elements that are already stored in the database.Now you can another int say i and using this i and x in the for loop you can create buttons dynamically.
Inside the loop you can do something like the following to get text for all the buttons that are being created:
TextHolder firstOne = getList.get(i);
String text = firstOne.getText();
You will also need class with getters and setters method in order to convert DB elements into objects.Like in the above code getText() is our getter method which is getting elements from database and returning it here.
here text will be the text of the button.
So every-time users starts the application he will see all the buttons that he created when he ran the application before and newly added button will appear on the spot and also will be stored in the database for future retrieval.
Remember we are just storing text of the button and assigning it unique id which helps us to create the buttons.Hope this helps
I have an app that dynamically adds EditText boxes in one method, and I want to use a button to clear those dynamic EditText boxes.
When they were created, I gave them integer IDs and I'm able to access the EditText variable in the activity. So how do I call that dynamic EditText box by its ID number and clear the text?
Why don't you just save a reference (or list of references) as Activity field? Populate the list and then onClick loop and clear. Doing it by ID is less efficient since you would have to perform a lookup
((EditText) findViewById(id)).setText("");
Reset edittext box on click the button
can.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
log.setText("");
pswd.setText("");
}
});
I want to execute one method wheneer i enter number in EditText view.But i did not change the focus of EditText.I am stay in the same EditText when i enter a new number automatically i eant to execute one function.Now my question is how we find that event that means enter a new number in EditText
You need to associate a TextWatcher to your EditText, and then, check in onTextChanged() if the character added was a number. You could use a regular expression for that :
if(s.matches("[0-9]")){
doYourStuffMethod();
}
You can also use the Matcher class from Android SDK which is an helper for this kind of stuff.