除了本身主要Activity的layout之外還要有一個要顯示在AlertDialog上的layout
在AlertDialog內的元件只能在
產生AlertDialog的時候findViewById 不然會FC
PS:!!!! 如果你的AlertDialog所用的Layout裡
只有一個EditText 且
EditText有加上<requestFocus />
那你的layout將會看不到... 我也不知道為什麼
//-----------取得alert Layout reference-------- LayoutInflater inflater = LayoutInflater.from(GoogleMapActivity.this); View alert_view = inflater.inflate(R.layout.alert,null);//alert為另外做給alert用的layout //-----------產生輸入視窗-------- AlertDialog.Builder builder = new AlertDialog.Builder(GoogleMapActivity.this); builder.setTitle(getString(R.string.alert_title)); builder.setMessage(getString(R.string.alert_msg)); builder.setView(alert_view); //alert.xml上的元件 要用屬於元件的view.才可以不然會FC也就是要加alert_view.findViewById input_longitude=(EditText)alert_view.findViewById(R.id.longitude); input_latitude=(EditText)alert_view.findViewById(R.id.latitude); //加入左右按鍵 不然的話直接 final AlertDialog dialog = builder.create(); 就好了 final AlertDialog dialog = builder.setPositiveButton(getString(R.string.alert_button_L), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { //如果未輸入提示使用者輸入 try{ geoPoint = new GeoPoint( (int)(Double.parseDouble(input_longitude.getText().toString()) * 1E6) , (int)(Double.parseDouble(input_latitude.getText().toString())* 1E6)); mapController.animateTo(geoPoint); }catch(Exception e){ } } }).setNegativeButton(getString(R.string.alert_button_R),new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { } }).create(); dialog.show();//把dialog秀出來
文章標籤
全站熱搜