不能解析符号QUOT;&的setText QUOT; SherlockActionBar片段 [英] cannot resolve symbol "setText" SherlockActionBar fragment

查看:351
本文介绍了不能解析符号QUOT;&的setText QUOT; SherlockActionBar片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序,我试着以测试功能的子片段。我们的想法是,该TextView的将更新,以模仿无论是进入的EditText。但是目前它不喜欢的setText,我不知道为什么。我检查,看看是否我已经错过了进口,我认为小部件正确定义。如何解决这个问题的任何意见将是巨大的。

 进口com.actionbarsherlock.app.SherlockFragment;
进口android.os.Bundle;
进口android.view.LayoutInflater;
进口android.view.View;
进口android.view.ViewGroup;
进口android.widget.EditText;
进口android.widget.TextView;公共类WeightFragment扩展SherlockFragment {@覆盖
公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,
                         捆绑savedInstanceState){
    查看rootView = inflater.inflate(R.layout.fragment_weight,集装箱,FALSE);
    返回rootView;
}重量的EditText =(EditText上)getActivity()findViewById(R.id.weightInput)。
TextView的标签=(TextView中)getActivity()findViewById(R.id.weightResult)。。字符串结果= weight.getText()的toString();
label.setText(结果);}


解决方案

把code里面的方法,如:

  @覆盖
公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,
                         捆绑savedInstanceState){
    查看rootView = inflater.inflate(R.layout.fragment_weight,集装箱,FALSE);    重量的EditText =(EditText上)getActivity()findViewById(R.id.weightInput)。
    TextView的标签=(TextView中)getActivity()findViewById(R.id.weightResult)。    。字符串结果= weight.getText()的toString();
    label.setText(结果);
    返回rootView;
}

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. However currently it doesn't like the setText and i have no idea why. 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;
}

这篇关于不能解析符号QUOT;&的setText QUOT; SherlockActionBar片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆