[英]cannot resolve symbol “setText” SherlockActionBar fragment
I have a child fragment in my application that im trying to test functionality in. The idea is that the textview will update to mimic whatever is entered into the edittext. 我的应用程序中有一个子片段,试图测试其功能。我的想法是,textview将更新以模仿在edittext中输入的内容。 However currently it doesn't like the setText and i have no idea why.
但是目前它不喜欢setText,我也不知道为什么。 I've checked to see whether i had missed an import and i think the widgets are defined correctly.
我检查了一下是否错过了导入,我认为这些小部件定义正确。 Any advice on how to solve this problem would be great.
关于如何解决此问题的任何建议都将是不错的。
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);
}
Put the code INSIDE a method, like this: 将代码放在方法中,如下所示:
@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.