我想在用戶單擊列表項時顯示一個popupwindow。我在我的片段的Adapter類中使用了initiatePopWindow()
。我如何解決findViewById
和ConfirmActivity
?無法解析Adapter類中的ConfirmActivity和findViewById
private void initiatePopupWindow() {
try {
//We need to get the instance of the LayoutInflater, use the context of this activity
LayoutInflater inflater = (LayoutInflater) ConfirmActivity.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//Inflate the view from a predefined XML layout
View layout = inflater.inflate(R.layout.popup_addword,
(ViewGroup) findViewById(R.id.popup_element));
// create a 300px width and 470px height PopupWindow
pw = new PopupWindow(layout, 300, 470, true);
// display the popup in the center
pw.showAtLocation(layout, Gravity.CENTER, 0, 0);
TextView WordPop = (TextView) layout.findViewById(R.id.textView2);
TextView PartsPop = (TextView) layout.findViewById(R.id.textView4);
TextView DescPop = (TextView) layout.findViewById(R.id.textView6);
TextView SentPop = (TextView) layout.findViewById(R.id.textView8);
WordPop.setText(list.getWord());
PartsPop.setText(list.getParts());
DescPop.setText(list.getDesc());
SentPop.setText(list.getDesc());
ImageButton cancelButton = (ImageButton) layout.findViewById(R.id.imageButton);
//makeBlack(cancelButton);
cancelButton.setOnClickListener(cancel_button_click_listener);
} catch (Exception e) {
e.printStackTrace();
}
}
因爲我是新手,可以舉個例子。 –
將代碼發佈到實例化適配器的位置。 –
db = new WordBookHandler(getActivity()); wordList = db.getAllWords(); adapter = new WordBookAdapter(getActivity(),wordList); listView.setAdapter(adapter); –