2019년 9월 16일 월요일

xml 변수 설정하기

안드로이드 개발할 시 주로 문자열을 string.xml 에서 관리합니다. 그런데 이 문자열 사이에 값이 달라지는 변수를 두고 싶을 때가 있습니다.

String.xml

<string name="hello">%1$s가 %2$s에게 인사합니다.</string> 

 %1$s : string  (문자열 일시)     %1$d : int   (숫자 일시)

JAVA
그리고 자바에서는 아래와 같이 코드를 해줍니다.


Resources res = getResources();

String text = String.format(res.getString(R.string.hello), "아이", "선생님"); 

결과값 -> 아이가 선생님에게 인사합니다.





영어권에서 복수형 단어 처리하기
영문으로 할 때에는 여러개일 경우에는 s가 붙는 거처럼 복수형 형태가 되는 경우가 있습니다.

String.xml


  <plurals name="file">


        
<item quantity="one">One file found.</item>


        
<item quantity="other">%d files found.</item>


    
</plurals>
 

%s : string   (문자열일경우)    %d : int    (숫자일경우)



JAVA

String.format(getResources().getQuantityString(R.plurals.file, 2), 4);
출력-> 4 files found.
String.format(getResources().getQuantityString(R.plurals.file, 1), 4);
출력-> One file found. 

출처: https://jhrun.tistory.com/123 [JHRunning]

2019년 8월 1일 목요일

중복계산

1
2
3
4
5
6
7
8
9
10
11
List<Group> _currentGroups =  SimulationManager.PageGroup.GetCurrentPage(); //PPAg
 
            int[] indexes = _currentGroups.Select(x => x.itemIdx).ToArray();
 
            GroupItem_Info[] groups = GroupContents.GetComponentsInChildren<GroupItem_Info>(); //UI
 
            int[] uiIndexes = groups.Select(x => x.objIdx).ToArray();
 
 
 
            int[] intercept = indexes.Intersect(uiIndexes).ToArray(); //중복되는idx 찾기
cs

2019년 7월 9일 화요일

oftype

1
List<FixtureItem> current_FixtureList = s_VirtualizingTreeViewDemo_DataItems.TreeView.SelectedItems.OfType<FixtureItem>().ToList();
cs

2019년 7월 8일 월요일

중복수 계산 LINQ

//Using extension methods
var q = list.GroupBy(x => x.Name)
            .Select(x => new {Count = x.Count(), 
                              Name = x.Key, 
                              ID = x.First().ID})
            .OrderByDescending(x => x.Count);

//Using LINQ
var q = from x in list
        group x by x.Name into g
        let count = g.Count()
        orderby count descending
        select new {Name = g.Key, Count = count, ID = g.First().ID};

foreach (var x in q)
{
    Console.WriteLine("Count: " + x.Count + " Name: " + x.Name + " ID: " + x.ID);
}

2019년 7월 1일 월요일

List next prev idx 구하기

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
int nextIdx =  (idx +1) % PageDatas.Count;
 
int prevIdx = (idx -1) % PageDatas.Count;
 
 
 
 
 
public void Next_Page()
 
    {
 
        int idx = PageDatas.IndexOf(currentPage);
 
        if (idx == PageDatas.Count-1)
 
            return;
 
 
 
        int nextIdx =  (idx +1) % PageDatas.Count;
 
        currentPage = PageDatas[nextIdx];
 
        Page_Text_Update();
 
    }
 
    public void Prev_Page()
 
    {
 
        int idx = PageDatas.IndexOf(currentPage);
 
        if (idx == 0)
 
            return;
 
        int prevIdx = (idx -1) % PageDatas.Count;
 
        currentPage = PageDatas[prevIdx];
 
        Page_Text_Update();
 
    }
cs

Unity UI stackoverflow error


error 나는 경우

public 하나가지고 get set하면 안됨 왜안되는지는 모르겠음
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public string Group_name {
 
        get
 
        {
 
            return Group_name;
 
        }
 
        set
 
        {
 
            Group_name = value;
 
            Group_name_text.text = Group_name;
 
        }
 
    }
 
 
cs




해결방법
변경하는거는 퍼블릭인 변수 Group_name으로 get set으로하고
내부에서는 private 변수인 _Group_name을 이용해서 원하는값을 지정한다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
private string _Group_name;
 
    public string Group_name {
 
        get
 
        {
 
            return _Group_name;
 
        }
 
        set
 
        {
 
            _Group_name = value;
 
            Group_name_text.text = _Group_name;
 
        }
 
    }
cs

git rejected error(feat. cherry-pick)

 문제 아무 생각 없이 pull을 받지않고 로컬에서 작업! 커밋, 푸시 진행을 해버렷다. push에선 remote와 다르니 당연히 pull을 진행해라고 하지만 로컬에서 작업한 내용을 백업하지 않고 진행하기에는 부담스럽다(로컬작업 유실 가능성) 해결하려...