我有一个onClick名称为checkResult
的按钮。
public void checkResult(View view){
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
LinearLayout myRoot = new LinearLayout(this);
View popupView = layoutInflater.inflate(R.layout.layout_result_popup, myRoot);
final PopupWindow popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
//what I want to show in the popup
TextView scorePopup = (TextView)findViewById(R.id.score_popup);
scorePopup.setText("Your score: " + score);
Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);
btnDismiss.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}});
popupWindow.showAsDropDown(checkResultButton, 100, -1200);
popupWindow.setFocusable(true);
popupWindow.update();
}
点击checkResult
按钮后,会显示layout_result_popup
。
我直接在主活动上放了一个按钮,并使用onClick来显示弹出窗口。到目前为止,我设法用XML显示弹出文本。但是当我尝试设置一些文本时,我的应用程序崩溃了。
请帮助。 :)
答案 0 :(得分:0)
尝试用这个代替这两行:
runOnUiThread(new Runnable() {
@Override
public void run() {
TextView countView = (TextView)findViewById(R.id.count);
countView .setText("Count: " + count+ "/" + totalCount);
}
});
它很可能适用于runOnUiThread