For now I'm using this algorithm:
List<String> constantListDataHeader = playersNames;
String[] listDataHeaderArray = new String[listDataHeader.size()];
playersNames.toArray(listDataHeaderArray);
...
EditText textsearch = view.findViewById(R.id.txtsearch);
textsearch.setOnEditorActionListener(new EditText.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
for (String item : listDataHeaderArray) {
if (item.toLowerCase().contains(textsearch.getText().toString().toLowerCase())) {
} else {
listDataHeader.remove(item);
}
}
return false;
}
return false;
}
});
The problem is the fact that if I try to perform search one more time, it won't work because the listDataHeader will consist of suitable for the previous search items only (listDataHeader.remove). Are there any other ways to perform search if I need it to work multiple times?
Related
Problem is on a service view back button is giving me a response but Home and Recent Apps button is not triggering
#Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_HOME: //Not getting
minimizeApp();
return true;
case KeyEvent.KEYCODE_BACK: //getting
finish(false);
return true;
case KeyEvent.KEYCODE_APP_SWITCH: //Not getting
//minimizeApp();
return true;
}
return true;
}
in the same service, I have tried to add and remove different flags but can't gets what I want.
mLayoutParams =new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL|
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN|
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON|
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
|WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
|WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
,
PixelFormat.TRANSLUCENT);
I am getting Back pressed but I want to catch Event of home and recent app pressed.
Updated
I got the solution
li = LayoutInflater.from(this);
LinearLayout lia= new LinearLayout(this) {
//home or recent button
public void onCloseSystemDialogs(String reason) {
if (reason.equals("homekey")){
finisha(false);
}
if (reason.equals("recentapps")){
finisha(false);
}
}
#Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK
|| event.getKeyCode() == KeyEvent.KEYCODE_APP_SWITCH
|| event.getKeyCode() == KeyEvent.KEYCODE_HOME
) {
//The Code Want to Perform.
// return true;
}
if (event.getKeyCode() == KeyEvent.KEYCODE_HOME){
}
if (event.getKeyCode() == KeyEvent.KEYCODE_APP_SWITCH){
}
return super.dispatchKeyEvent(event);
}
};
lia.setFocusable(true);
final View root = (View) li.inflate(R.layout.layout_alias_locker, lia);
I am trying to disable left and right on the keyboard with this code but viewPager on the press of left and right button change the state of the pager.
edComment.setOnEditorActionListener(
new EditText.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS
|| actionId == EditorInfo.IME_FLAG_NAVIGATE_NEXT
|| actionId == EditorInfo.IME_ACTION_PREVIOUS
|| actionId == EditorInfo.IME_ACTION_NEXT
) {
return false;
}
// Return true if you have consumed the action, else false.
return false;
}
});
You can extend the ViewPager and override the arrowScroll method like this:
public class Wizard extends ViewPager {
#Override
public boolean arrowScroll(int direction) {
// Never allow pressing keyboard arrows to switch between pages
return false;
}
}
The keyboard app can show whatever keys it wants. There is no way to force it not to show certain buttons, and even if there was another keyboard wouldn't follow the same rules.
According to #Gabe Sechan button are not hide or disable so I am doing like that
#Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
Log.i("your tag", "Keycode: " + keyCode);
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
Log.e("Click","left");
/* for (int n = 0; n < count; n++) {
setCurrentPage(arrayListView.get(n + 1));
}*/
pager.setCurrentItem(getItem(+1), true);
return true;
case KeyEvent.KEYCODE_DPAD_RIGHT:
Log.e("Click","right");
pager.setCurrentItem(getItem(-1), true);
return true;
case KeyEvent.KEYCODE_DPAD_UP:
Log.e("Click","up");
return true;
case KeyEvent.KEYCODE_DPAD_DOWN:
Log.e("Click","Down");
return true;
default:
return super.onKeyUp(keyCode, event);
}
}
I have 4 editText, and I want to store all the values in String arrayList. I have declared my arrayList globally. I can get the correct size of my arrayList, but I can't get any String value. Here's my code:
editText.setOnEditorActionListener(new TextView.OnEditorActionListener()
{
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
if(actionId == EditorInfo.IME_ACTION_DONE)
{
//get the user name
String player1 = editText.getText().toString();
playerName.add(player1);
}
return false;
}
});
editText1.setOnEditorActionListener(new TextView.OnEditorActionListener()
{
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
if(actionId == EditorInfo.IME_ACTION_DONE)
{
//get the user name
playerName.add(editText.getText().toString());
}
return false;
}
});
editText2.setOnEditorActionListener(new TextView.OnEditorActionListener()
{
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
if(actionId == EditorInfo.IME_ACTION_DONE)
{
//get the user name
playerName.add(editText.getText().toString());
}
return false;
}
});
editText3.setOnEditorActionListener(new TextView.OnEditorActionListener()
{
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
if(actionId == EditorInfo.IME_ACTION_DONE)
{
//get the user name
playerName.add(editText.getText().toString());
}
return false;
}
});
First, correct the listener, you use the same editText everywhere when you get the text editText.getText().toString().
Note : You could update this to use 1 instance of listener but that a different question.
To read a List, use List.get(int) or iterate it like
for(int i = 0; i < list.size(); ++i){
String s = list.get(i);
...
}
or
for(String s : list){
...
}
Now, did you need to use a listener, or could you just get the value when you need it ? That your project but that's an idea. Because did you want to stack the value if you input a value twice in the same EditText?
playerName.get(index);
you can get the string object you need from ArrayList in this way
try this:
//declare global
ArrayList<EditText> editextList = new ArrayList<>();
ArrayList<String> editextValuesList = new ArrayList<>();
onCreate(){
//bind edittext and then
editextList.add(editText);
editextList.add(editText1);
editextList.add(editText2);
editextList.add(editText3);
//you can use below lines anywhere if any text changes in edittext then it will give you updated text
for(int i=0;i<edittextList.size();i++){
String editTextString = edittextList.get(i).getText().toString();
editextValuesList.add(editTextString);
}
}
To get a single player, please try this code:
String player1 = playerName.get(0);
To get all the players from the list, please use this code:
for (String player : playerName) {
Log.d("TAG", player);
}
Hope it helps.
I'm trying to cacth done action which comes from softkeyboard. My code is like this;
private TextView.OnEditorActionListener getDoneListener() {
return new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
nextPage();
return true;
}
else {
return false;
}
}
};
}
However even though IDE evaluates "(actionId == EditorInfo.IME_ACTION_DONE)"as true, it's not calling nextPage(), returning false instead. If I cast expression like this, it works fine.
private TextView.OnEditorActionListener getDoneListener() {
return new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if ((boolean)(actionId == EditorInfo.IME_ACTION_DONE)) {
processPayment();
return true;
}
else {
return false;
}
}
};
}
Any idea what can cause this?
I have four edittext (atm pin kind of thing) and I want to validate all these four edittext on click of keypads done button(validations like - empty or wrong pin). so far, I could get the validations but it happens only if I click the done buttn twice. not able to figure out the issue, please help. I am a beginner. thanks!
Below is my code :
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.pin_new);
setTextFocus(edtpin1, edtpin2);
setTextFocus(edtpin2, edtpin3);
setTextFocus(edtpin3, edtpin4);
setTextFocus(edtpin5, edtpin6);
setTextFocus(edtpin6, edtpin7);
setTextFocus(edtpin7, edtpin8);
edtpin1.setOnEditorActionListener(new OnEditorActionListener(){
#Override
public boolean onEditorAction(TextView v, int arg1, KeyEvent arg2) {
switch (v.getId()) {
case R.id.btnBackPin:
Intent i = new Intent(getApplicationContext(),RegistrationProfileEmail.class);
startActivity(i);
break;
case R.id.btnCancelPin:
Intent in = new Intent(getApplicationContext(),Exit.class);
finish();
startActivity(in);
break;
case R.id.btnConfirmPin:
String s = new String();
s = edtpin1.getText().toString() + edtpin2.getText().toString()
+edtpin3.getText().toString() + edtpin4.getText().toString();
if ((edtpin5.getText().toString().trim().isEmpty())
|| (edtpin1.getText().toString().trim().isEmpty())
|| (edtpin2.getText().toString().trim().isEmpty())
|| (edtpin4.getText().toString().trim().isEmpty())
|| (edtpin3.getText().toString().trim().isEmpty())
|| (edtpin6.getText().toString().trim().isEmpty())
|| (edtpin7.getText().toString().trim().isEmpty())
|| (edtpin8.getText().toString().trim().isEmpty())) {
Toast.makeText(getApplicationContext(), "Enter the Pin",
Toast.LENGTH_SHORT).show();
edtpin1.setText(null);
edtpin2.setText(null);
edtpin3.setText(null);
edtpin4.setText(null);
edtpin5.setText(null);
edtpin6.setText(null);
edtpin7.setText(null);
edtpin8.setText(null);
edtpin1.requestFocus();
}
else if (edtpin1.getText().toString().trim().equalsIgnoreCase(edtpin5.getText().toString().trim())&& edtpin2.getText().toString().trim().equalsIgnoreCase(
edtpin6.getText().toString().trim()) && edtpin3.getText().toString().trim().equalsIgnoreCase( edtpin7.getText().toString().trim()) && edtpin4.getText().toString().trim().equalsIgnoreCase( edtpin8.getText().toString().trim()))
{
s = edtpin1.getText().toString() + edtpin2.getText().toString()
+ edtpin3.getText().toString()
+ edtpin4.getText().toString();
RegistrationPin.this.setPin(s);
}
// TODO move to payment option
else {
Toast.makeText(getApplicationContext(), "Pin is not matching",Toast.LENGTH_SHORT).show();
edtpin1.setText(null);
edtpin2.setText(null);
edtpin3.setText(null);
edtpin4.setText(null);
edtpin5.setText(null);
edtpin6.setText(null);
edtpin7.setText(null);
edtpin8.setText(null);
edtpin1.requestFocus();
}
break;
default:
break;
}
return false;
}
});
}
Create a class and implement the textwatcher like this:
private class CheckTextifEmpty implements TextWatcher {
#Override
public void afterTextChanged(Editable s) {
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
if (isEmptyCharacters(serverNumber)
|| isEmptyCharacters(textview1)
|| isEmptyCharacters(textview2)
|| isEmptyCharacters(textview3)) {
//do something here
} else {
//do something here
}
}
}
and add this method here:
private boolean isEmptyCharacters(TextView v) {
return v.getText().toString().trim().isEmpty();
}
and use it in your textview like this:
textview1.addTextChangedListener(new CheckTextIfEmpty());
You can use your validation like this without using a button
Refactor your code like this:
private boolean checkifValidate(TextView view1,View TextView2){
return view1.getText().toString().trim().contentEquals(view2.getText().toString());
}
Hope it helps,
edtpin1.setOnKeyListener(onSoftKeyboardDonePress);
private View.OnKeyListener onSoftKeyboardDonePress=new View.OnKeyListener()
{
public boolean onKey(View v, int keyCode, KeyEvent event)
{
if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
{
edtpin1.getText().toString();
edtpin2.getText().toString();
edtpin3.getText().toString();
edtpin4.getText().toString();
}
return false;
}
};