android - 自定义类中的布局膨胀问题
问题描述
我正在尝试扩展 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();
}
});
}
有了这个,我可以访问另一个视图的元素,这是我想要的一部分,但特别是视图没有显示出来。我错过了什么吗?
解决方案
anchorview.addView(theInflatedView) 可以帮助你吗?
推荐阅读
- winapi - 使用多个调色板绘制 4bpp 2D 瓷砖的最佳方法是什么?
- node.js - 试图在命令上运行 execsync 但不断得到...不被识别为内部
- ffmpeg - ffmpeg rtsp 记录段和文件夹-文件名
- python - 从 Python 和 PostgreSQL 中提取星期几时的差异,有什么解决方案吗?
- python - 如何使用 OCR Pytesseract 删除文本提取后出现的箭头符号
- amazon-web-services - AWS CLI:api gateway get-usage 不返回所有密钥的使用情况
- javascript - 如何在 Amp 上创建添加到主屏幕?
- reactjs - prevstate 有什么用?
- azure - 升级 Azure SQL 服务器
- python - 如何知道一个进程是否从python中的cron启动