首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >findViewById在三星平板电脑上返回null

findViewById在三星平板电脑上返回null
EN

Stack Overflow用户
提问于 2016-05-05 05:39:05
回答 1查看 188关注 0票数 0

这似乎是一个常见的问题,提出了许多解决方案,但我没有成功地解决它。

除了创建expandableListview的调用之外,所有对findViewById的调用都是成功的。而且它似乎依赖于设备。它适用于Android Studio,也适用于Moto E 4G (5.0.2),但不适用于三星Galaxy Tab 8.0 (5.1.1)。

完整的项目可以在github上找到:https://github.com/JohanDegraeve/helpdiabetes-android有问题的模块是https://github.com/JohanDegraeve/helpdiabetes-android/blob/master/app/src/main/java/com/hippoandfriends/helpdiabetes/Show/Food/ShowSelectedFood.java如果有人可以克隆这个项目并尝试修复它,那将是非常有帮助的。

在这里,创建expandablelistview的onCreate方法返回null。

代码语言:javascript
运行
复制
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    View contentView = LayoutInflater.from(getParent()).inflate(
            R.layout.show_selected_food, null);
    setContentView(contentView);

    // track we come here
    ActivityGroupMeal.group.parent
            .trackPageView(TrackingValues.pageShowSelectedFood);

    expandOrNotDBAdapater = new DbAdapter(this);
    expandOrNotDBAdapater.open();

    functions = new Functions();

    mCalendar = Calendar.getInstance();

    btDelete = (Button) findViewById(R.id.buttonDelete);
    btSaveTemplate = (Button) findViewById(R.id.buttonSaveAsTemplate);
    btLoadTemplate = (Button) findViewById(R.id.buttonLoadTemplate);
    btAddSelectedFoodToTracking = (Button) findViewById(R.id.buttonAddSelectedFoodToTracking);

    btBack = (Button) findViewById(R.id.buttonBack);
    btBack.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            ActivityGroupMeal.group.back();
        }
    });

    expandableListview = (ExpandableListView) findViewById(R.id.expandableListview);

    saveFoodAmount = false;

    fInsulineRatio = 0f;
    fCorrectionFactor = 0f;
    fCalculatedInsulineAmount = 0f;

    dbHelper = new DbAdapter(this);

    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);

    adapter = new CustomExpandableListAdapter(this,
            ActivityGroupMeal.group.getFoodData().dbFontSize,
            metrics.densityDpi);

    listOfSelectedFood = new ArrayList<DBSelectedFood>();
    registerForContextMenu(getListView());

    btAddSelectedFoodToTracking.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            onClickAddSelectedFoodToTracking();
        }
    });

    btDelete.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // track we come here
            ActivityGroupMeal.group.parent.trackEvent(
                    TrackingValues.eventCategoryMeal,
                    TrackingValues.eventCategoryMealDeleteSelectedFood);

            onClickDeleteAll(v);
        }
    });

    btSaveTemplate.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // track we come here
            ActivityGroupMeal.group.parent.trackEvent(
                    TrackingValues.eventCategoryMeal,
                    TrackingValues.eventCategoryMealSaveTemplate);

            onClickSaveAsTemplate(v);
        }
    });

    btLoadTemplate.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // track we come here
            ActivityGroupMeal.group.parent.trackEvent(
                    TrackingValues.eventCategoryMeal,
                    TrackingValues.eventCategoryMealLoadTemplate);

            onClickLoadTemplate(v);
        }
    });

    expandableListview
            .setOnGroupExpandListener(new OnGroupExpandListener() {
                public void onGroupExpand(int groupPosition) {
                    setExpand(1);
                }
            });

    expandableListview
            .setOnGroupCollapseListener(new OnGroupCollapseListener() {
                public void onGroupCollapse(int groupPosition) {
                    setExpand(0);
                }
            });
}
EN

回答 1

Stack Overflow用户

发布于 2016-05-08 06:12:43

已解决

实际上,在平板电脑上,缺少id的地方使用了另一种布局

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37038512

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档