동적으로 spniier를 추가했는데 spinner를 선택하면 어플리케이션이 죽어버리네요
context문제 같은데 어디를 고쳐야 할 지 모르겠습니다ㅜㅜ
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test__smsanalysis);
checkSMSConent();
DBHelper dbHelper = new DBHelper(this);
context = this;
ArrayList<String> arrayList = new ArrayList<>();
arrayList = dbHelper.selectDistintByCompany();
ImageView imageView;
for (int i = 0; i < arrayList.size(); i++) {
if (arrayList.get(i).equals("농협카드")) {
imageView = (ImageView) this.findViewById(R.id.imageView);
imageView.setVisibility(View.VISIBLE);
} else if (arrayList.get(i).equals("신한카드")) {
imageView = (ImageView) this.findViewById(R.id.imageView2);
imageView.setVisibility(View.VISIBLE);
} else {
}
}
///
final ImageButton btnOpenPopup = (ImageButton) findViewById(R.id.imageButton);
btnOpenPopup.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(final View arg0) {
LayoutInflater layoutInflater
= (LayoutInflater) getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
final View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
popupWindow.setFocusable(true);
edittext = (EditText) popupWindow.getContentView().findViewById(editText);
edittext.isLongClickable();
Button findButton = (Button) popupView.findViewById(R.id.smsButton);
final LinearLayout topLL = (LinearLayout)popupView.findViewById(R.id.smsLayout);
findButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
String inPutText = edittext.getText().toString();
//textView.setText(checkSpecialSMSConent(inPutText)[1]);
////
int temp = checkSpecialSMSConent(inPutText).length;
TextView[] topTV1 = new TextView[temp];
LinearLayout[] linearLayouts = new LinearLayout[temp];
Spinner[] spinners = new Spinner[temp];
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,
android.R.layout.simple_spinner_item, item);
for(int i = 0;i < checkSpecialSMSConent(inPutText).length;i++ ){
//////
linearLayouts[i] = new LinearLayout(view.getContext());
spinners[i] = new Spinner(view.getContext());
linearLayouts[i].setOrientation(LinearLayout.HORIZONTAL);
spinners[i].setAdapter(adapter);
//////
topTV1[i] = new TextView(view.getContext());
topTV1[i].setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
topTV1[i].setBackgroundColor(Color.parseColor("#00FFFFFF"));
topTV1[i].setPadding(20, 10, 10, 10);
topTV1[i].setTextColor(Color.parseColor("#FF7200"));
topTV1[i].setTextSize(13);
topTV1[i].setText(checkSpecialSMSConent(inPutText)[i]);
linearLayouts[i].addView(spinners[i]);
linearLayouts[i].addView( topTV1[i]);
topLL.addView(linearLayouts[i]);
}
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.carmoneybook.myapplication, PID: 11429
android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@42fc4988 is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:780)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:278)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.widget.PopupWindow.invokePopup(PopupWindow.java:1087)
at android.widget.PopupWindow.showAsDropDown(PopupWindow.java:974)
at android.widget.ListPopupWindow.show(ListPopupWindow.java:635)
at android.widget.Spinner$DropdownPopup.show(Spinner.java:1176)
at android.widget.Spinner.performClick(Spinner.java:685)
at android.view.View$PerformClick.run(View.java:19416)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5635)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)