Skip to content

Instantly share code, notes, and snippets.

@chamoda
Created January 17, 2017 09:34
Show Gist options
  • Save chamoda/443742484d9e0682ee6ca55e96c86478 to your computer and use it in GitHub Desktop.
Save chamoda/443742484d9e0682ee6ca55e96c86478 to your computer and use it in GitHub Desktop.
Autogenerate android butterknife binding code from xml
#! /usr/bin/python
#
# Chamoda Panthage
# chamodac@gmail.com
#
import fileinput
from bs4 import BeautifulSoup
xml = ''
for line in fileinput.input():
xml += line
soup = BeautifulSoup(xml, 'xml')
elements = soup.find_all(lambda tag: 'android:id' in tag.attrs)
print('\n')
for element in elements:
print '@BindView(R.id.' + element['android:id'].split("/")[1] + ') ' + element.name + ' ' + element['android:id'].split("/")[1] + ';'
print('\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment