728x90

안드로이드 달력 만들기 MainActivity.java 와 GridCellAdapter.java 파일에서 아래와 같이 ArrayList 제네릭으로 HashMap<String, String> 을 사용하는 방법이다.


ArrayList<Calendar_Item> calList = new ArrayList<>();

ArrayList<HashMap<String, String>> calList = new ArrayList<>();

로 변경하여 코딩하면 어떻게 처리해야 할까?


Calendar_Item 이 HashMap<String, String> 라는 것으로 변경된 것만 살펴보고 수정해주면 된다.


    private Calendar_Item calendarItem(String year, String month, String day, int weekday, String color, String name, String key){
        Calendar_Item item = new Calendar_Item();
        item.setYear(year);
        item.setMonth(month);
        item.setDay(day);
        item.setWeekday(weekday);
        item.setColor(color);
        item.setEvent(name);
        item.setKey(key);
        return item;
    }

    private void addCalendarItem(String year, String month, String day, int weekday, String color,String name, String key){
        Calendar_Item item = calendarItem(year,month,day,weekday,color,name,key);
        calList.add(item);
    }

    private int getIndexOfCalList(String search_key) {
        for (int temp = 0; temp < calList.size(); temp++) {
            String key = calList.get(temp).getKey();
            if (key != null && key.equals(search_key)) {
                return temp;
            }
        }
        return -1;
    }
 

    private HashMap<String, String> calendarItem(String year, String month, String day, int weekday, String color, String name, String key){
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("year",year);
        map.put("month",month);
        map.put("day",day);
        map.put("weekday", String.valueOf(weekday));
        map.put("color",color);
        map.put("event",name);
        map.put("key",key);
        return map;
    }

    private void addCalendarItem(String year, String month, String day, int weekday, String color,String name, String key){
        HashMap<String, String> item = calendarItem(year,month,day,weekday,color,name,key);
        calList.add(item);
    }

    private int getIndexOfCalList(String search_key) {
        for (int temp = 0; temp < calList.size(); temp++) {
            String key = calList.get(temp).get("key");
            if (key != null && key.equals(search_key)) {
                return temp;
            }
        }
        return -1;
    }


GridCellAdapter 에서 변경해줄 것은 아래와 같다.

    private final ArrayList<Calendar_Item> calList;


    public GridCellAdapter(Context context, ArrayList<Calendar_Item> list) {
        mContext = context;
        calList = list;
    }

    public Calendar_Item getItem(int position) {
        return calList.get(position);
    }


        String theday = calList.get(position).getDay();
        int themonth = Integer.parseInt(calList.get(position).getMonth());
        String theyear = calList.get(position).getYear();
        String holiday = calList.get(position).getEvent();
 

    private final ArrayList<HashMap<String, String>> calList;


    public GridCellAdapter(Context context, ArrayList<HashMap<String, String>> list) {
        mContext = context;
        calList = list;
    }


    public HashMap<String, String> getItem(int position) {
        return calList.get(position);
    }

        String theday = calList.get(position).get("day");
        int themonth = Integer.parseInt(calList.get(position).get("month"));
        String theyear = calList.get(position).get("year");
        String holiday = calList.get(position).get("event");
 


ArrayList<HashMap<String, String>> 를 사용하면 아래와 같은 Calendar_Item Class 를 만들 필요가 없어 코드가 좀 더 간단해질 수 있다.

public class Calendar_Item {
    private  String year; // 년
    private  String month; // 월
    private  String day; // 일
    private  int weekday; // 요일
    private  String color; // 색상
    private String event;
    private String key; // 월일 값을 key 로 사용

    public Calendar_Item() {
    }

    public Calendar_Item(String year, String month, String day, int weekday, String color) {
        this.year = year;
        this.month = month;
        this.day = day;
        this.weekday = weekday;
        this.color = color;
    }

    public String getYear() {
        return year;
    }

    public void setYear(String year) {
        this.year = year;
    }

    public String getMonth() {
        return month;
    }

    public void setMonth(String month) {
        this.month = month;
    }

    public String getDay() {
        return day;
    }

    public void setDay(String day) {
        this.day = day;
    }

    public int getWeekday() {
        return weekday;
    }

    public void setWeekday(int weekday) {
        this.weekday = weekday;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public String getEvent() {
        return event;
    }

    public void setEvent(String event) {
        this.event = event;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }
}


블로그 이미지

Link2Me

,
728x90

새로운 Moudle 를 추가했더니 이런 에러가 발생한다.

Manifest merger failed with multiple errors, see logs


보통 다른 블로그에 나온 경우와는 다른 황당한 경우다.


public class Calendar_Item {
    private  String year; // 년
    private  String month; // 월
    private  String day; // 일
    private  int weekday; // 요일
    private  String color; // 색상
    private String event;
    private String key; // 월일 값을 key 로 사용


처음에 이름을 name 으로 했다가 rename 으로 일괄 event 로 변경했더니......

프로젝트내의 모든 AndroidManifest.xml 파일과

res/values/ 하단 파일들이 모두 name → event 로 변경되어 있더라. ㅠㅠ


이런 황당한 경우가 있다니....

그러다보니 AndroidManifest.xml 이 비정상적이다보니 이런 에러메시지를 보여줬던 거다.


모두 수작업으로 EditPlus 에서 event= → name= 로 변경해주고 나서야 정상이 되었다.


변수를 사용할 때 절대로 name 과 같은 걸 사용해서는 안되겠다는 걸 알게 되었다.



블로그 이미지

Link2Me

,