我在使用方法 showList 的 onCreate 方法中有一个 imageView。这是代码:
action_bar_log_in_icon.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
allResults.clear();
allResults.add(action_bar_log_in_icon);
allResults.add(action_bar_data_privacy_icon);
allResults.add(action_bar_vCard_icon);
allResults.add(action_bar_email_icon);
showList();
}
});
和代码方法showList:
private void showList() {
final ListDialog listDialog = new ListDialog(this);
listDialog.setCanceledOnTouchOutside(true);
final ListView lv = (ListView) listDialog
.findViewById(R.id.spinnerlist);
if(lAdapter == null){
lAdapter = new ListAdapter(getBaseContext(),
R.layout.spinner_item,
(ArrayList<ImageView>) allResults);
}
lv.setAdapter(lAdapter);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
switch(position){
case 0:
intent = new Intent(ActionBarMain2.this, LoginActivity.class);
startActivity(intent);
break;
case 1:
intent = new Intent(ActionBarMain2.this, LoginActivity.class);
startActivity(intent);
break;
case 2:
intent = new Intent(ActionBarMain2.this, vCard_view.class);
startActivity(intent);
break;
case 3:
intent = new Intent(ActionBarMain2.this, EmailView.class);
startActivity(intent);
break;
}
listDialog.dismiss();
}
});
WindowManager.LayoutParams WMLP = listDialog.getWindow()
.getAttributes();
WMLP.gravity = Gravity.TOP | Gravity.RIGHT;
WMLP.y = 50;
WMLP.width = 100;
listDialog.getWindow().setAttributes(WMLP);
listDialog.show();
}
此解决方案有效,如果我单击 imageview 我的列表将显示,但问题是当我再次单击同一个 imageview 时。列表仍然可见。当我第一次单击我的列表显示时以及当我再次单击我的列表关闭等时,我该怎么办?