我在popUp窗口中有一个listView,我希望当用户点击listview中的某个项目时,popUp窗口会自动关闭。知道我该怎么做吗?
<script type="text/javascript">
function myFormat(num){
return (num < 10)? ("0"+num): num;
}
function StartTimer(num, time){
this.parts = time.split(':');
this.hours = this.parts[0];
this.minutes = this.parts[1];
this.seconds = this.parts[2];
this.span = $('#countdown' + num);
}
StartTimer.prototype.myTimer = function(){
var s = this.seconds;
var m = this.minutes;
var h = this.hours;
var sp = this.span;
var t = setInterval(function(){
s--;
if(s == -1) {
s = 59;
m--;
if(m == -1) {
m = 59;
h--;
if(h == -1) {
alert("timer finished");
clearInterval(t);
return;
}
}
}
//console.log();
//console.log();
//console.log();
sp.text(h + ":" + myFormat(m) + ":" + myFormat(s));
}, 1000);
};
</script>
答案 0 :(得分:3)
将此代码放在alert.show();
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
String from_language = ((TextView)view).getText().toString();
Toast.makeText(getBaseContext(), from_language, Toast.LENGTH_LONG).show();
// CLOSE POPUP WINDOW
alert.dismiss();
}
});
答案 1 :(得分:2)
您可以通过更改对话框的初始化顺序来执行此操作:
public void popUp(){
final ListView promptView = new ListView(this);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setView(promptView);
// setup a dialog window
alertDialogBuilder.setCancelable(false)
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
// create an alert dialog
final AlertDialog alert = alertDialogBuilder.create();
String[] languages = {"Arabic","Bulgarian","Catalan"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, languages);
promptView.setAdapter(adapter);
promptView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
String from_language = ((TextView)view).getText().toString();
Toast.makeText(getBaseContext(), from_language, Toast.LENGTH_LONG).show();
// CLOSE POPUP WINDOW
alert.dismiss();
}
});
alert.show();
}