Android在ListView点击事件中关闭AlertDialog
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android在ListView点击事件中关闭AlertDialog相关的知识,希望对你有一定的参考价值。
ArrayList<Person> list = initData();
final AlertDialog.Builder builder;
AlertDialog alertDialog;
// Context context = getApplicationContext();
Context context = TestBt.this;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
final View layout = inflater.inflate(R.layout.test, (ViewGroup) findViewById(R.id.lttest));
ListView myListView = (ListView) layout.findViewById(R.id.mylistview);
TestAd adapter = new TestAd(context, list);
myListView.setAdapter(adapter);
builder = new AlertDialog.Builder(context);
builder.setView(layout);
myListView.setOnItemClickListener(new OnItemClickListener()
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
String str_dest = ((Person) parent.getItemAtPosition(position)).getName();
ed_test.setText(str_dest);
layout.setVisibility(View.GONE);
);
alertDialog = builder.create();
alertDialog.show();
我想在myListView.setOnItemClickListener事件中关闭AlertDialog
Android中关闭DatePickerTimePickerNumberPicker的可编辑模式
DatePicker、TimePicker、NumberPicker这三个控件在使用的过程中,用户点击数字会弹出键盘,有时候会造成布局被挤压不好看,也有其他的需求。
我看了网上很多文章的解决办法都无效,后来还是万能的StackOverflow网站帮我解决了这个问题,代码如下:
- mDatePicker.setDescendantFocusability(DatePicker.FOCUS_BLOCK_DESCENDANTS);
- mTimePicker.setDescendantFocusability(TimePicker.FOCUS_BLOCK_DESCENDANTS);
- //NumberPicker同理
以上是关于Android在ListView点击事件中关闭AlertDialog的主要内容,如果未能解决你的问题,请参考以下文章
Android中关闭DatePickerTimePickerNumberPicker的可编辑模式