lantianyiming 2013-05-08 03:22 采纳率: 0%
浏览 10080
已采纳

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 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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记