class을 Catch The Cows에서 다운로드했습니다. Google지도 개체와 유사하거나 최소한 내가 사용하고있는 개체입니다.프로그래밍 방식으로 R.ID를 설정합니다
터치 할 수 있어야하는 화면의 영역을 나열한 XML 파일을 구문 분석 한 다음이 메서드를 사용하여 XML 파일을 만듭니다. 이 컨텍스트 여기에, 나는 코드의 일부를 주석 처리하고, 추가 된 내 자신을 내 문제가 화면에 렌더링 된
private Area addShape(String shape, String name, String coords, String id) {
Log.v("IDS:", "id was "+id);
Area a = null;
String rid = id.replace("@+id/", "");
Log.v("IDS:", "rid was "+rid);
// Generate a new ID for the area.
int _id = 1;
View vi = findViewById(_id);
while (vi!=null) {
_id++;
vi = findViewById(_id);
}
//View.generateViewId(); //=0;
Log.v("IDS:", "After conversion final time "+_id);
/*
try {
Class<R.id> res = R.id.class;
Field field = res.getField(rid); // eg. rid = area10
_id = field.getInt(null);
Log.v("IDS:", "After conversion "+_id);
}
catch (Exception e) {
_id = 0;
Log.e("Exception ",e.getMessage());
} finally {
Log.v("IDS:", "After conversion final time "+_id);
}
*/
if (_id != 0) {
if (shape.equalsIgnoreCase("rect")) {
String[] v = coords.split(",");
if (v.length == 4) {
a = new RectArea(_id, name, Float.parseFloat(v[0]),
Float.parseFloat(v[1]),
Float.parseFloat(v[2]),
Float.parseFloat(v[3]));
}
}
if (shape.equalsIgnoreCase("circle")) {
String[] v = coords.split(",");
if (v.length == 3) {
a = new CircleArea(_id,name, Float.parseFloat(v[0]),
Float.parseFloat(v[1]),
Float.parseFloat(v[2])
);
}
}
if (shape.equalsIgnoreCase("poly")) {
a = new PolyArea(_id,name, coords);
}
if (a != null) {
addArea(a);
}
} else {
Log.v("Loading ID: ","_id was 0");
}
return a;
}
불행하게도 아무것도 시도하지하고 해결하고,이이었다 때문에 _id = 0 .이 코드의이 비트와 함께 변경해야합니다 :
try {
Class<R.id> res = R.id.class;
Field field = res.getField(rid); // eg. rid = area10
_id = field.getInt(null);
}
어떻게 지금까지 나는 그것을 시도하고 디버그가, 사람이 조각이 무엇을하고 있는지 설명 할 수 무엇 확실하지 않다?
입니다. 올바르게 서식을 지정하여 기회를주십시오. – Simon
이미 완료 - 실수로 코드 섹션보다는 블록 코멘트를 기록했습니다. –
'Resources' 클래스에는'id'를 "이름": getIdentifier ("id", "area10", context.getPackage())'를 얻을 수있는'getIdentifier()'메소드가 있습니다. – Luksprog