1
我已經閱讀了許多有關這個常見問題的論壇,但無法在我的應用程序中解決它。 在我的android應用程序中,我需要顯示一個彈出窗口,其中有一個窗體具有編輯文本和保存按鈕。當用戶點擊保存按鈕時,應該刷新彈出窗口。我曾嘗試解僱的方法,但:-(Android PopupWindow解僱問題
Javacode:
LayoutInflater inflater = (LayoutInflater) ListActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View popUp_layout = inflater.inflate(R.layout.popup_example,(ViewGroup) findViewById(R.id.popup_form_add_quote));
final PopupWindow popUp = new PopupWindow(inflater.inflate(R.layout.popup_example, null, false), 430, 300, true);
popUp.setBackgroundDrawable(new BitmapDrawable());
popUp.setOutsideTouchable(true);
// popUp.showAtLocation(popUp_layout, Gravity.CENTER, 10, 10);
Button save_Button = (Button) popUp_layout.findViewById(R.id.save_quote_button);
AlertDialog.Builder builder = new AlertDialog.Builder(this).setView(popUp_layout);
AlertDialog alertDialog = builder.create();
alertDialog.show();
save_Button = (Button) alertDialog.findViewById(R.id.save_quote_button);
if (save_Button != null) {
save_Button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("Save button clicked.");
popUp.dismiss();
}
});
}
XML/widget_info.xml
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:initialLayout="@layout/widget_layout"
android:minHeight="82dp"
android:minWidth="246dp"
android:updatePeriodMillis="1000" >
繪製-MDPI/myshape.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<stroke android:width="2dp" vandroid:color="#FFFFFFFF" />
<gradient android:angle="225" android:endColor="#DD2ECCFA" android:startColor="#DD000000" />
<corners android:bottomLeftRadius="7dp" android:bottomRightRadius="7dp" android:topLeftRadius="7dp" android:topRightRadius="7dp" />
佈局/ popup_example.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/popup_form_add_quote"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#C0CAE0"
android:orientation="vertical"
android:padding="10dip" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="Quote" />
<EditText
android:id="@+id/quote_text"
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="left"
android:layout_weight="0.80"
android:ems="10"
android:inputType="textMultiLine"
android:lines="4"
android:maxLines="4" >
<requestFocus />
</EditText>
<CheckBox
android:id="@+id/quote_status_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enable/Disable" />
<Button
android:id="@+id/save_quote_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Save" />
嗨,我已經複製了上面的代碼,並在我的項目中創建了一個Java文件。但是它顯示了getContext()方法的編譯錯誤。它無法找到它。 –
適合我工作。編譯對API級別15?你如何創建你的對話框? – Leandros
我正在創建popupwindow。哎呀..我有API 10,因爲我正在起訴SDK 2.3.3 :-( –