簡體   English   中英

無法解析符號“ setText” SherlockActionBar片段

[英]cannot resolve symbol “setText” SherlockActionBar fragment

我的應用程序中有一個子片段,試圖測試其功能。我的想法是,textview將更新以模仿在edittext中輸入的內容。 但是目前它不喜歡setText,我也不知道為什么。 我檢查了一下是否錯過了導入,我認為這些小部件定義正確。 關於如何解決此問題的任何建議都將是不錯的。

import com.actionbarsherlock.app.SherlockFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

public class WeightFragment extends SherlockFragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_weight, container, false);
    return rootView;
}

EditText weight = (EditText) getActivity().findViewById(R.id.weightInput);
TextView label = (TextView) getActivity().findViewById(R.id.weightResult);

String result = weight.getText().toString();
label.setText(result);

}

將代碼放在方法中,如下所示:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_weight, container, false);

    EditText weight = (EditText) getActivity().findViewById(R.id.weightInput);
    TextView label = (TextView) getActivity().findViewById(R.id.weightResult);

    String result = weight.getText().toString();
    label.setText(result);
    return rootView;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM