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

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 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败