lantianyiming
lantianyiming
2013-05-08 03:22
采纳率: 79.6%
浏览 9.2k

fragment中的setContentView

需要将activity转化成fragment。代码在setContentView报错/

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_googlev2);
    Init();
    addMarkersToMap();
    yStart = 21.102918;
    yEnd = 20.960798;
    xStart = 105.772762;
    xEnd = 105.900650;
    xNow = xStart;
    yNow = yStart;
    adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_dropdown_item_1line);
    textView = (AutoCompleteTextView) getView().findViewById(R.id.autoCompleteTextView1);
    textView.setThreshold(3);
    adapter.setNotifyOnChange(true);
    textView.setAdapter(adapter);
    textView.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count){
            autoCount = count;
            autoS = s;
            if(autoCount % 3 == 1) {
                stCommand = "AutoCompleteTextView";
                lp = new ExecuteTask();
                lp.execute();
            }
        }
        public void beforeTextChanged(CharSequence s, int start, int count, int after){ // TODO Auto-generated method stub
        }
        public void afterTextChanged(Editable s){
        }
    });
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • Kill_it
    Kill_it 2013-05-08 07:20
    已采纳

    重写onCreatView:

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {             
        View rootView = inflater.inflate(R.layout.activity_googlev2, container, false);
        return rootView;
    }
    
    点赞 评论
  • franzhong
    franzhong 2013-05-08 04:06

    Fragment 不能这样操作View
    查阅如下方法:

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)     
    public void onViewCreated(View view, Bundle savedInstanceState) 
    
    点赞 评论
  • cj6585256
    码密码密哄 2013-05-08 06:51

    可以这样操作

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
               return infalter.inflater(R.layout.activity_googlev2,null);
    }
    
    点赞 评论

相关推荐