我有彈出窗口,從我的AsyncTask獲取的內容列表視圖列表視圖,我已經從我的asyctask加我的內容mcodeList(聲明爲ArrayList<String>
)。
我檢查的內容&這是樣品mcodeList從日誌:列表視圖上的彈出式窗口未出現
Response : > [08-00631 can be found in LAB A, 08-00635 can be found in LAB A]
當我得到的內容mcodeList這種情況下,我不希望這樣的節目直接在彈出窗口等等我不設置listview適配器onPostExecute
。但我希望當我點擊按鈕彈出窗口時,listview的內容(mcodeList)將出現在彈出窗口中。
這是我在彈出窗口代碼:
try {
LinearLayout viewGroup = (LinearLayout) findViewById(R.id.popup_element);
LayoutInflater inflater = (LayoutInflater) ListLocationActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.list_popup, viewGroup);
pWindow = new PopupWindow();
pWindow.setContentView(layout);
pWindow.setWidth(300);
pWindow.setHeight(200);
pWindow.showAtLocation(layout, Gravity.CENTER, 0, 0);
Log.d("Response : ", "> "+ mcodeList);
// Updating parsed JSON data into listview
ListView lv_popup = (ListView) findViewById(R.id.list_info);
lv_popup.setAdapter(new ArrayAdapter<String>(this, R.layout.popup, R.id.mcode, mcodeList));
btnClose = (Button)layout.findViewById(R.id.btn_close);
btnClose.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
pWindow.dismiss();
}
});
} catch(Exception e) {
e.printStackTrace();
}
這是我的彈出窗口的佈局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/popup_element"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background ="#B2FFFF"
android:orientation="vertical" >
<ListView android:id="@+id/list_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#B2E0FF"
android:dividerHeight="1dp"/>
<Button android:id="@+id/btn_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Close" />
</LinearLayout>
,這我的列表項的佈局:
<TextView
android:id="@+id/mcode"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
和我的第一個問題是當我點擊按鈕彈出窗口時,彈出窗口出現,但是listview沒有顯示。第二個問題是當我點擊關閉按鈕時,我無法關閉popupwindow,這就像我的程序崩潰,但仍然在運行。
,我得到這樣的警告日誌是這樣的:
D/AbsListView(17047): Get MotionRecognitionManager
W/System.err(17047): java.lang.NullPointerException
W/System.err(17047): at com.example.assetscanner.ListLocationActivity.initiatePopupWindow(ListLocationActivity.java:442)
W/System.err(17047): at com.example.assetscanner.ListLocationActivity.infoAsset(ListLocationActivity.java:457)
W/System.err(17047): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err(17047): at java.lang.reflect.Method.invoke(Method.java:511)
W/System.err(17047): at android.view.View$1.onClick(View.java:3655)
W/System.err(17047): at android.view.View.performClick(View.java:4162)
W/System.err(17047): at android.view.View$PerformClick.run(View.java:17082)
W/System.err(17047): at android.os.Handler.handleCallback(Handler.java:615)
W/System.err(17047): at android.os.Handler.dispatchMessage(Handler.java:92)
W/System.err(17047): at android.os.Looper.loop(Looper.java:137)
W/System.err(17047): at android.app.ActivityThread.main(ActivityThread.java:4867)
W/System.err(17047): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err(17047): at java.lang.reflect.Method.invoke(Method.java:511)
W/System.err(17047): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
W/System.err(17047): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
W/System.err(17047): at dalvik.system.NativeStart.main(Native Method)
我從來沒有發現這樣的錯誤,所以請有人能幫助我。 感謝的前
來把你的所有代碼 –