我正在尝试在我的应用程序中使用提及类型弹出窗口,当弹出窗口出现时,用户滚动,然后继续键入弹出窗口解除。有没有办法让弹出窗口保持打开状态,直到我们调用dismiss?
这是我正在使用的代码。
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();
}
}
});
}
}