我正在尝试添加addtextchangedlistener
一个 EDITTEXT,它在我的 Fragment1.java 中可用,它扩展了 SherlockFragment。
我已经粘贴了我的 Fragment1.java 文件和我的更新日志猫,上面有错误。
发布了我的完整代码
package org.kp.tp.reachout;
import org.kp.tp.general.R;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.MultiAutoCompleteTextView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import com.actionbarsherlock.app.SherlockFragment;
public class ReachoutActivity extends SherlockFragment {
private RadioGroup radioSexGroup;
EditText sendmail_subject, sendmail_message;
Spinner spinner2;
MultiAutoCompleteTextView spinner1;
RadioButton doctors, specialization;
public void enableSubmitIfReady(View v) {
boolean sendmailSubject = sendmail_subject.getText().toString()
.length() > 0;
boolean sendmailMessage = sendmail_message.getText().toString()
.length() > 0;
doctors = (RadioButton) v.findViewById(R.id.radioMale);
specialization = (RadioButton) v.findViewById(R.id.radioFemale);
if (sendmailSubject && sendmailMessage) {
radioSexGroup.setVisibility(View.VISIBLE);
if(doctors.isChecked()){
spinner1.setVisibility(View.VISIBLE);
}
else if (specialization.isChecked()){
spinner2.setVisibility(View.VISIBLE);
}
} else {
radioSexGroup.setVisibility(View.GONE);
spinner1.setVisibility(View.GONE);
spinner2.setVisibility(View.GONE);
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View v = inflater.inflate(R.layout.fragment_reachout, container, false);
sendmail_subject = (EditText) v.findViewById(R.id.sendmail_subject);
sendmail_message = (EditText) v.findViewById(R.id.sendmail_message);
spinner1 = (MultiAutoCompleteTextView) v.findViewById(R.id.sendmail_tousers);
spinner2 = (Spinner) v.findViewById(R.id.sendmail_tohubs);
Log.e("subject",sendmail_subject.getText().toString());
sendmail_subject.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
enableSubmitIfReady(v);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
enableSubmitIfReady(v);
}
});
sendmail_message.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
enableSubmitIfReady(v);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
enableSubmitIfReady(v);
}
});
return v;
}
}
并记录 cat 文件。
08-31 06:32:21.714: E/AndroidRuntime(3277): FATAL EXCEPTION: main
08-31 06:32:21.714: E/AndroidRuntime(3277): java.lang.NullPointerException
08-31 06:32:21.714: E/AndroidRuntime(3277): at org.kp.tp.reachout.ReachoutActivity.enableSubmitIfReady(ReachoutActivity.java:40)
08-31 06:32:21.714: E/AndroidRuntime(3277): at org.tpt.docglobal.reachout.ReachoutActivity$2.onTextChanged(ReachoutActivity.java:107)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.widget.TextView.sendOnTextChanged(TextView.java:7318)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.widget.TextView.handleTextChanged(TextView.java:7377)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:9076)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.text.SpannableStringBuilder.sendTextChanged(SpannableStringBuilder.java:962)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:496)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:435)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:30)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.text.method.QwertyKeyListener.onKeyDown(QwertyKeyListener.java:223)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.text.method.TextKeyListener.onKeyDown(TextKeyListener.java:136)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.widget.TextView.doKeyDown(TextView.java:5464)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.widget.TextView.onKeyDown(TextView.java:5283)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.KeyEvent.dispatch(KeyEvent.java:2623)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.View.dispatchKeyEvent(View.java:7343)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.widget.ScrollView.dispatchKeyEvent(ScrollView.java:353)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
08-31 06:32:21.714: E/AndroidRuntime(3277): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1933)
08-31 06:32:21.714: E/AndroidRuntime(3277): at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1408)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.app.Activity.dispatchKeyEvent(Activity.java:2384)
08-31 06:32:21.714: E/AndroidRuntime(3277): at com.actionbarsherlock.app.SherlockFragmentActivity.dispatchKeyEvent(SherlockFragmentActivity.java:121)
08-31 06:32:21.714: E/AndroidRuntime(3277): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1860)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:3791)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3774)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3483)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3540)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3516)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3666)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:1982)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1698)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1689)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:1959)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
08-31 06:32:21.714: E/AndroidRuntime(3277): at android.os
08-31 06:32:25.274: I/Process(3277): Sending signal. PID: 3277 SIG: 9