亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

實施時如何修復文本更改偵聽器錯誤?

實施時如何修復文本更改偵聽器錯誤?

眼眸繁星 2023-05-10 13:52:39
我在 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"            >
查看完整描述

1 回答

?
開心每一天1111

TA貢獻1836條經驗 獲得超13個贊

我認為錯誤是您的 XML 代碼將編輯文本標記為fiftythres. 在您的代碼中,您將其設置為:

fiftythinput = rootView.findViewById(R.id.fiftyinput);

你需要做的是:

fiftythinput = (EditText)rootView.findViewById(R.id.fiftythinput);

希望能幫助到你!如果沒有,請通知我。


查看完整回答
反對 回復 2023-05-10
  • 1 回答
  • 0 關注
  • 136 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號