Reputation: 854
I am trying to get a mention type popup working in my app and when the popup window comes up, the user scrolls, and then continues typing the popup window dismisses. Is there any way to keep the popup window open until we call dismiss?
Here's the code I'm working with.
public class MainActivity extends AppCompatActivity
{
private EditText editText;
private ListPopupWindow listPopup;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (EditText) findViewById(R.id.editText);
String[] states = getResources().getStringArray(R.array.state_array);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, states);
listPopup = new ListPopupWindow(this);
listPopup.setHeight(300);
listPopup.setAnchorView(editText);
listPopup.setAdapter(adapter);
//listPopup.setModal(false);
listPopup.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Toast.makeText(MainActivity.this, "Position " + String.valueOf(position) + " Clicked", Toast.LENGTH_SHORT).show();
}
});
editText.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
if(!listPopup.isShowing())
{
listPopup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NEEDED);
listPopup.show();
listPopup.getListView().setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
editText.requestFocus();
}
}
});
}
}
Upvotes: 2
Views: 124
Reputation: 31
I had a similar issue, even if I set the INPUT_METHOD_NEEDED
flag, the ListPopupWindow
implementation overrode it while resizing the popup.
My solution was to force inputMethodMode = INPUT_METHOD_NEEDED
everytime I made changes in the list adapter. This solved the flashy popup visibility changes and the popup stayed in place even with adapter updates.
Something like
fun updatesAdapterItems(list: List<Items>) {
inputMethodMode = INPUT_METHOD_NEEDED
adapter.submitList(list)
}
Upvotes: 0