जोड़ने में असमर्थ मैं EditText
में एक लंबा क्लिक करने की कोशिश कर रहा हूं, लेकिन जब मैं एक लंबा क्लिक करता हूं, तो मुझे नीचे त्रुटि मिलती है। मैं कॉपी/पेस्ट/सभी संदर्भ पॉपअप का चयन करने के लिए एक लंबा क्लिक करने में सक्षम होना चाहता हूं ताकि उपयोगकर्ता बॉक्स में टेक्स्ट पेस्ट कर सके।लंबे समय तक संपादित करें टेक्स्टटास्ट क्रैश: विंडो
Fatal Exception: android.view.WindowManager$BadTokenException: Unable to add window -- token [email protected] is not valid; is your activity running?
एडिटटेक्स्ट पॉपअपविंडो में स्क्रॉल व्यू में है। तो जब त्रुटि होती है, तो मैं वर्तमान में पॉपअपविंडो के साथ एक गतिविधि पर सक्रिय हूं और मैं पॉपअपविंडो पर मौजूद संपादन टेक्स्ट के अंदर एक लंबा क्लिक करता हूं।
Gradle सेटिंग
compileSdkVersion 25
buildToolsVersion '25.0.0'
defaultConfig {
applicationId 'com.accoservice.cico'
minSdkVersion 17
targetSdkVersion 25
versionCode 37
versionName '4.2.6'
multiDexEnabled true
}
लेआउट EditText युक्त:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/outer_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#73000000">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="100dp"
android:layout_marginBottom="5dp"
android:background="#ffffff"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="15dp"
android:singleLine="true"
android:text="@string/note_msg"
android:textColor="#62CCFE"
android:textSize="18sp" />
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="10dp"
android:background="#62CCFE" />
<ScrollView
android:id="@+id/sv_resolution_note"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp">
<EditText
android:id="@+id/et_note_msz"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/view"
android:layout_alignParentTop="true"
android:scrollbars="vertical"
android:focusable="true"
android:gravity="left"
android:maxLines="20"
android:hint="@string/write_note"
android:inputType="textFilter|textMultiLine|textCapSentences"
android:singleLine="false"
android:textIsSelectable="true"
android:enabled="true"
android:longClickable="true" />
</ScrollView>
<View
android:id="@+id/view"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_above="@+id/send_note"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@android:color/darker_gray" />
<Button
android:id="@+id/send_note"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/viewss"
android:layout_gravity="center"
android:background="@color/white"
android:text="@string/add_note" />
<View
android:id="@+id/viewss"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@android:color/darker_gray" />
</LinearLayout>
</LinearLayout>
पॉप अप विंडो:
@Override
public void onClick(View v) {
noteDialog(getResources().getString(R.string.laborentryresolutionstart), tv_labor_entry_resolution_start);
}
public void noteDialog(String noteTitle, final TextView tv_resolution_note)
{
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
final View popupView;
popupView = layoutInflater.inflate(R.layout.resolution_note, null);
TextView title = (TextView) popupView.findViewById(R.id.title);
title.setText(noteTitle);
final EditText editText = (EditText) popupView.findViewById(R.id.et_note_msz);
final PopupWindow popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
popupWindow.update();
popupWindow.setFocusable(true);
popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
editText.setEnabled(false);
editText.setEnabled(true);
editText.setFocusable(true);
editText.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
//ADD HERE ABOUT CUT COPY PASTE
// TODO Auto-generated method stub
return false;
}
});
if (!tv_resolution_note.getText().toString().isEmpty()) {
editText.setText(tv_resolution_note.getText().toString());
}
Button btnDone = (Button) popupView.findViewById(R.id.send_note);
LinearLayout outer_layout = (LinearLayout) popupView.findViewById(R.id.outer_layout);
outer_layout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
popupWindow.dismiss();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.RESULT_HIDDEN, 0);
}
});
System.gc();
try {
btnDone.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
EditText noteMsz = (EditText) popupView.findViewById(R.id.et_note_msz);
tv_resolution_note.setText(noteMsz.getText().toString());
popupWindow.dismiss();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.RESULT_HIDDEN, 0);
invalidateOptionsMenu();
}
});
} catch (Exception e) {
}
popupWindow.setFocusable(true);
popupWindow.setBackgroundDrawable(new BitmapDrawable(null, ""));
popupWindow.showAsDropDown(tv_labor_sym_entry, 0, -60);
popupWindow.update();
}
क्या आप इस कोड को गतिविधि में कॉल कर रहे हैं? एक सेवा? क्या आप वाकई एक गतिविधि के लिए स्क्रीन से बाहर नहीं गए हैं? यह संदेश आमतौर पर तब होता है जब आप किसी सेवा से यूआई लॉन्च करने का प्रयास करते हैं, या जब आप गतिविधि के बाद एक संवाद पॉप अप करने का प्रयास करते हैं। –
मैं गतिविधि पर रहते हुए पॉपअप विंडो के लिए कोड कॉल कर रहा हूं। गतिविधि वर्तमान में चल रही है, पॉपअप विंडो सक्रिय है और मैं EditText में एक लंबी प्रेस करता हूं और त्रुटि प्राप्त करता हूं। – Adam
मैंने एमुलेटर एपीआई 24 पर एक मामूली संशोधन के साथ अपना कोड चलाया और यह मेरे लिए ठीक काम करता है। यही कहना है कि यह क्रैश नहीं हो रहा है और लंबे प्रेस श्रोता को अपेक्षित के रूप में बुलाया जाता है। क्या आप चीजों को सेट अप करने के बारे में कुछ और जानकारी प्रदान कर सकते हैं? एपीआई जिस पर आप परीक्षण कर रहे हैं? [यहां] (https://gist.github.com/Cheticamp/08ebef491a727a12577a7e9790eaa752) उस गतिविधि का एक सारांश है जिसका उपयोग मैंने आपकी मदद की है। – Cheticamp