Android在ListView点击事件中关闭AlertDialog
ArrayList<Person>list=initData();finalAlertDialog.Builderbuilder;AlertDialogalertDial...
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 展开
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 展开
2016-08-09 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
listview1.requestFocus();加上这句看看??在dialog.show()的后面
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询