一经解雇,是否可以再次显示android中的popupWindow?我做不到

时间:2018-12-27 19:57:57

标签: android popupwindow dismiss onbackpressed

我的android项目中有一个Activity。 单击按钮,将显示一个popupWindow。 一切正常,直到我在popupWindow中按下并返回活动状态,然后再次单击Button。一切冻结,应用程序停止。

我的popupWindow具有自定义视图。其视图由SearchView,ExpandableListView和要提交的Button组成。 expandableListView检索电话联系人。 我搜索了问题,但他们在按下后背时解雇存在问题,这不是我要解决的问题。

Button import_contact = findViewById(R.id.import_contact);
import_contact.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
    LayoutInflater inflater = (LayoutInflater)
    getSystemService(LAYOUT_INFLATER_SERVICE);
    View popupView = inflater.inflate(R.layout.import_contacts_window, null);
    int width = LinearLayout.LayoutParams.MATCH_PARENT;
    int height = LinearLayout.LayoutParams.MATCH_PARENT;
    PopupWindow popupWindow = new PopupWindow(popupView, width, height, true);
    popupWindow.setOutsideTouchable(true);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.GRAY));
    popupWindow.setContentView(popupView);
    popupWindow.showAtLocation(findViewById(R.id.contacts_container), Gravity.CENTER, 0, 0);
    popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            Log.e("dismiss", "true");
        }
    });

    contactsListView = popupView.findViewById(R.id.phone_contacts_list);
    contactsListDataAdapter = new ContactListAdapter(MainActivity.this,
                                expandableListTitle,
                                expandableListDetail);
    DisplayMetrics metrics = new DisplayMetrics();                    
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int w = metrics.widthPixels;
    contactsListView.setIndicatorBounds(w - 30, w - 6);                    
    contactsListView.setAdapter(contactsListDataAdapter);
    SearchManager searchManager = (SearchManager) 
    getSystemService(Context.SEARCH_SERVICE);
    search = popupView.findViewById(R.id.searchContacts);
    search.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    search.setIconifiedByDefault(false);
    search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            Log.e("onQueryTextSubmit", "1");
            return false;
        }
        @Override
        public boolean onQueryTextChange(String newText) {
            Log.e("onQueryTextChange", " ");
            contactsListDataAdapter.filterData(newText);
            expandAll();
            return true;
        }
    });
    search.setOnCloseListener(new SearchView.OnCloseListener() {
        @Override
        public boolean onClose() {
            Log.e("onClose", " ");
            return false;
        }
    });
    Button OK = popupView.findViewById(R.id.OK);
    OK.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
        // TODO: verify OK from Client with a popup dialog
        }
    });
    if (!hasPhoneContactsPermission(Manifest.permission.READ_CONTACTS)) {                    
        requestPermission(Manifest.permission.READ_CONTACTS, PERMISSION_REQUEST_CODE_READ_CONTACTS);
    } else {
        readPhoneContacts();
    }
}
});

这是关闭popupwindow之后以及我按下按钮以重新打开popupWindow之后的日志:

12-27 03:57:31.925 16287-16287/com.ghasedakia E/dismiss: true
12-27 03:57:31.925 16287-16287/com.ghasedakia W/InputEventReceiver: 
Attempted to finish an input event but the input event receiver has already 
been disposed.
12-27 03:57:50.765 151-179/? W/AudioPolicyManagerBase: getOutput() could not 
find output for stream 1, samplingRate 0,format 0, channels 3, flags 0
12-27 03:57:50.765 151-151/? W/AudioPolicyManagerBase: getOutput() could not 
find output for stream 1, samplingRate 0,format 0, channels 3, flags 0
12-27 03:57:50.765 151-11050/? W/AudioPolicyManagerBase: getOutput() could 
not find output for stream 1, samplingRate 44100,format 1, channels 1, flags 
4
12-27 03:57:50.765 313-426/system_process E/AudioTrack: Could not get audio 
output for stream type 1
12-27 03:57:50.765 313-426/system_process E/SoundPool: Error creating 
AudioTrack
12-27 03:57:50.905 493-496/com.android.phone D/dalvikvm: GC_CONCURRENT freed 
384K, 6% free 11238K/11847K, paused 0ms+0ms, total 2ms

经过一段时间后,应用程序崩溃并显示以下日志:

12-27 04:34:12.977 313-392/system_process I/InputDispatcher: Application is 
not responding: Window{53799ea0 com.ghasedakia/com.ghasedakia.MainActivity 
paused=false}.  It has been 5003.3ms since event, 5003.3ms since wait started.  
Reason: Waiting because the touched window has not finished processing the input 
events that were previously delivered to it.
12-27 04:34:12.977 313-392/system_process I/WindowManager: Input event 
dispatching timed out sending to com.ghasedakia/com.ghasedakia.MainActivity
12-27 04:34:12.981 313-392/system_process I/Process: Sending signal. PID: 16861 
SIG: 3
12-27 04:34:12.989 16861-16866/com.ghasedakia I/dalvikvm: threadid=3: reacting 
to signal 3
12-27 04:34:12.989 313-316/system_process D/dalvikvm: GC_CONCURRENT freed 784K, 
15% free 13983K/16391K, paused 1ms+1ms, total 10ms
12-27 04:34:13.001 16861-16866/com.ghasedakia I/dalvikvm: Wrote stack traces to 
'/data/anr/traces.txt'
12-27 04:34:13.005 313-392/system_process I/Process: Sending signal. PID: 313     
SIG: 3
12-27 04:34:13.005 313-318/system_process I/dalvikvm: threadid=3: reacting to 
signal 3
12-27 04:34:13.077 313-325/system_process E/Sensors: Select fail, disconnect all 
clients (errno=4)
12-27 04:34:13.089 313-318/system_process I/dalvikvm: Wrote stack traces to 
'/data/anr/traces.txt'
12-27 04:34:13.113 313-392/system_process I/Process: Sending signal. PID: 493 
SIG: 3
12-27 04:34:13.113 493-500/com.android.phone I/dalvikvm: threadid=3: reacting to 
signal 3
12-27 04:34:13.113 313-316/system_process D/dalvikvm: GC_CONCURRENT freed 42K, 
15% free 13941K/16391K, paused 11ms+11ms, total 26ms
12-27 04:34:13.141 493-500/com.android.phone I/dalvikvm: Wrote stack traces to 
'/data/anr/traces.txt'
12-27 04:34:13.141 313-392/system_process I/Process: Sending signal. PID: 432 
SIG: 3
12-27 04:34:13.141 432-437/com.android.systemui I/dalvikvm: threadid=3: reacting 
to signal 3
12-27 04:34:13.153 432-437/com.android.systemui I/dalvikvm: Wrote stack traces 
to '/data/anr/traces.txt'
12-27 04:34:13.201 313-316/system_process D/dalvikvm: GC_CONCURRENT freed 521K, 
14% free 14148K/16391K, paused 12ms+1ms, total 24ms
12-27 04:34:13.201 313-392/system_process D/dalvikvm: WAIT_FOR_CONCURRENT_GC 
blocked 12ms
12-27 04:34:13.205 313-392/system_process D/dalvikvm: GC_EXPLICIT freed 17K, 14% 
free 14131K/16391K, paused 0ms+1ms, total 8ms
12-27 04:34:13.713 313-392/system_process E/ActivityManager: ANR in 
com.ghasedakia (com.ghasedakia/.MainActivity)
Reason: keyDispatchingTimedOut
        Load: 0.69 / 0.34 / 0.45
        CPU usage from 7981ms to 0ms ago:
        99% 16861/com.ghasedakia: 99% user + 0% kernel
        100% TOTAL: 99%   user + 0.2% kernel
        CPU usage from  227ms to 731ms later:
        94% 16861/com.ghasedakia: 94% user + 0% kernel
        94% 16861/com.ghasedakia: 94% user + 0% kernel
        100% TOTAL: 100%   user + 0% kernel
12-27 04:34:13.749 313-316/system_process D/dalvikvm: GC_CONCURRENT freed 412K, 
12% free 14568K/16391K, paused 12ms+1ms, total 27ms
12-27 04:34:13.749 313-16887/system_process D/dalvikvm: WAIT_FOR_CONCURRENT_GC 
blocked 16ms
12-27 04:34:13.757 313-16887/system_process D/dalvikvm: GC_FOR_ALLOC freed 459K, 
13% free 14275K/16391K, paused 9ms, total 9ms
12-27 04:34:16.081 313-325/system_process D/Sensors: Client connection accepted 
(232)

我看到了此页面, https://blog.csdn.net/geekqian/article/details/70279076

我认为问题和我一样。但是我不能setFocusable设为假,因为我需要处理popupWindow上的点击。

我希望每次单击按钮时,都会显示popupWindow。但是第二次我触摸按钮时,应用程序冻结。有什么想法可以解决问题吗?

0 个答案:

没有答案