我在 Android Studio 中遇到文本更改侦听器的一些问题。我正在使用 Fragment,当我运行它时,Logcat 上没有显示任何内容。我确定我在 XML 文件中输入了文本编辑。我也检查了 id,没有出现错误。
请告诉我为什么 Logcat 中没有弹出任何内容。
public class FirstFragment extends Fragment {
public static final String ARG_PAGE = "ARG_PAGE";
private int mPage;
private EditText fiftythinput;
private TextView fiftythres;
TextWatcher textWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
Log.v("tag_t","2");
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
Log.v("tag_t","3");
}
@Override
public void afterTextChanged(Editable editable) {
Log.v("tag_t","1");
}
};
public static FirstFragment newInstance(int page){
Bundle args = new Bundle();
args.putInt(ARG_PAGE, page);
FirstFragment blankFragment = new FirstFragment();
blankFragment.setArguments(args);
return blankFragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_first, container, false);
fiftythinput = (EditText)rootView.findViewById(R.id.fiftyinput);
fiftythres = (TextView)rootView.findViewById(R.id.fiftyres);
fiftythinput.addTextChangedListener(textWatcher);
return rootView;
}
}
________添加 XML________
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
开心每一天1111
相关分类