Reputation: 4201
I have an XML layout with 20-25 similar rows which are used to set different parameters. The rows contain an AutoCompleteTextView
and an ImageButton
. Whenever an option is set within one of these views, a method is called to set the variable in my code, and then refresh all of the views. There are three ways each variable can be set...AutoCompleteTextView:
OnKeyListener, OnItemSelectedListener....ImageButton:
OnClickListener
Here is an example of this part of one of the rows:
pumpCountAutoText = new AutoCompleteTextView( this );
pumpCountAutoText.setHint( R.string.anti_pump_pump_count_hint );
pumpCountAutoText.setTextSize( 12.0f );
pumpCountAutoText.setLayoutParams( editLP );
pumpCountAutoText.setThreshold( 1 );
pumpCountAutoText.setId( 11001 );
pumpCountAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, pumpCountList);
pumpCountAutoText.setAdapter( pumpCountAdapter );
pumpCountAutoText.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// if keydown and "enter" is pressed
if ((event.getAction() == KeyEvent.ACTION_DOWN)
&& (keyCode == KeyEvent.KEYCODE_ENTER)) {
String item = pumpCountAutoText.getText().toString();
hideSoftKeyboard( MoreParameters.this );
pumpCountAutoText.dismissDropDown();
if( hasRead ) {
if(pumpCountList.contains( item ) ) {
if( !( item.equals( " " ) ) ) {
int val = Integer.parseInt( item );
//Log.i( "pumpCountSpinner", Integer.toString( val ) );
RelayAPIModel.NativeCalls.SetParmJava( RelayAPIModel.PARM_PUMPCOUNT, val );
}
}
}
return true;
}
return false;
}
});
pumpCountAutoText.setOnItemClickListener( new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
hideSoftKeyboard( MoreParameters.this );
String item = pumpCountAutoText.getText().toString();
if( !( item.equals( " " ) ) ) {
int val = Integer.parseInt( item );
//Log.i( "pumpCountSpinner", Integer.toString( val ) );
RelayAPIModel.NativeCalls.SetParmJava( RelayAPIModel.PARM_PUMPCOUNT, val );
}
}
});
pumpCountDropdownButton = new ImageButton( this );
pumpCountDropdownButton.setLayoutParams( dropLP );
pumpCountDropdownButton.setId( 11002 );
pumpCountDropdownButton.setImageResource( R.drawable.arrow_down_float );
pumpCountDropdownButton.setOnClickListener( new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog.Builder ab=new AlertDialog.Builder(MoreParameters.this);
ab.setTitle( R.string.anti_pump_pump_count_hint );
ab.setItems( pumpCountList.toArray( new String[pumpCountList.size()]), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int pos ) {
String item = pumpCountList.get( pos );
if( !( item.equals( " " ) ) ) {
int val = Integer.parseInt( item );
RelayAPIModel.NativeCalls.SetParmJava( RelayAPIModel.PARM_PUMPCOUNT, val );
}
}
});
ab.show();
}
});
My problem is that after any of these items are set, the text field at the top of my screen automatically gets focused and displays the dropdown menu for that view. It is extremely annoying. I want to select an item in any view and not have these dropdowns appear.
I have tried two things:
1) I have added AutoCompleteTextView.setCursorVisible( false );
2) And I have also tried this:
specialCTAutoText.setFocusable( false );
specialCTAutoText.setFocusableInTouchMode( false );
specialCTAutoText.setText( temp );
specialCTAutoText.setFocusable( true );
specialCTAutoText.setFocusableInTouchMode( true );
The second thing I tried is called when all of my views are refreshed in the second method which is not shown here. This works fine. However, once I edit a textview one of those three ways, it still auto selects the top edittext view.
I hope this is clear enough, but any clarification needed let me know.
Upvotes: 1
Views: 599
Reputation: 1007369
However, once I edit a textview one of those three ways, it still auto selects the top edittext view.
Try calling requestFocus()
on some other widget at the point in time when you "edit a textview one of those three ways".
Upvotes: 2