首页 > 解决方案 > 自定义类中的布局膨胀问题

问题描述

我正在尝试扩展 xml 布局,但我在执行此操作时遇到了问题。

我创建了一个名为“DebugHelper”的自定义类,我收到了

class DebugHelper {    
    void drawGrid(final Application context, final View anchorview) {
    
       map.setOnPolygonClickListener(new GoogleMap.OnPolygonClickListener(){
        public void onPolygonClick(Polygon polygon) {

                    LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );

                    inflater = LayoutInflater.from(context); // 1
                    View theInflatedView = inflater.inflate(R.layout.classification_map, null); 
                    TextView a = (TextView) theInflatedView.findViewById(R.id.textView4);

                    Toast.makeText(context, a.getText(),
                            Toast.LENGTH_LONG).show();

                }

    });


}

有了这个,我可以访问另一个视图的元素,这是我想要的一部分,但特别是视图没有显示出来。我错过了什么吗?

标签: android

解决方案


anchorview.addView(theInflatedView) 可以帮助你吗?


推荐阅读