안드로이드 개발 질문/답변
(글 수 45,052)
현재 main.xml 에서 버튼을 사용하여
다른 category1.xml, category2.xml, category3.xml ....... 으로 넘어가는걸 구현하고있습니다.
main에서 버튼 배치까지 다 하고 특정 버튼을 누르면 category1.xml로 넘어가고 그리고 다른 버튼을 누르면 category2.xml로
넘어가는 것을 구현했는데 이게 이상하게
category1.xml의 수가 많아질수록 버튼의 구현도 계속 해서 늘어나네요
ex)
보통 버튼을 사용해서 다른 xml로 넘어갈때 다음코드를 사용하는데요
Button launch = (Button)findViewById(R.id.Button01);
launch.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v)
{
Intent intent = new Intent(SCactive.this, category1.class);
startActivity(intent);
}
});
그런데 이게 버튼의 갯수가 많아지니
Button
launch = (Button)findViewById(R.id.Button01),
launch2 = (Button)findViewById(R.id.Button02),
launch3 = (Button)findViewById(R.id.Button03),
launch4 = (Button)findViewById(R.id.Button04),
launch5 = (Button)findViewById(R.id.Button05),
launch6 = (Button)findViewById(R.id.Button06),
launch7 = (Button)findViewById(R.id.Button07);
launch.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v)
{
Intent intent = new Intent(SCactive.this, category1.class);
startActivity(intent);
}
});
launch2.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent(SCactive.this, category2.class);
startActivity(intent);
}
});
...................
.................
.............
이런식으로 쓸데없이 줄이 길어지네요그래서 launch 같은건 포인터로 돌릴수도 있겟는데
category <- 이건 따로 포인터를 어떻게 놓는지 모르겟네요
아니면 다른방식으로 xml에서 다른 xml로 가는 방식이 있는지모르겟어요
다른 category1.xml, category2.xml, category3.xml ....... 으로 넘어가는걸 구현하고있습니다.
main에서 버튼 배치까지 다 하고 특정 버튼을 누르면 category1.xml로 넘어가고 그리고 다른 버튼을 누르면 category2.xml로
넘어가는 것을 구현했는데 이게 이상하게
category1.xml의 수가 많아질수록 버튼의 구현도 계속 해서 늘어나네요
ex)
보통 버튼을 사용해서 다른 xml로 넘어갈때 다음코드를 사용하는데요
Button launch = (Button)findViewById(R.id.Button01);
launch.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v)
{
Intent intent = new Intent(SCactive.this, category1.class);
startActivity(intent);
}
});
그런데 이게 버튼의 갯수가 많아지니
Button
launch = (Button)findViewById(R.id.Button01),
launch2 = (Button)findViewById(R.id.Button02),
launch3 = (Button)findViewById(R.id.Button03),
launch4 = (Button)findViewById(R.id.Button04),
launch5 = (Button)findViewById(R.id.Button05),
launch6 = (Button)findViewById(R.id.Button06),
launch7 = (Button)findViewById(R.id.Button07);
launch.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v)
{
Intent intent = new Intent(SCactive.this, category1.class);
startActivity(intent);
}
});
launch2.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent(SCactive.this, category2.class);
startActivity(intent);
}
});
...................
.................
.............
이런식으로 쓸데없이 줄이 길어지네요그래서 launch 같은건 포인터로 돌릴수도 있겟는데
category <- 이건 따로 포인터를 어떻게 놓는지 모르겟네요
아니면 다른방식으로 xml에서 다른 xml로 가는 방식이 있는지모르겟어요




어플 하나에 메뉴 달릴때마다 쫙쫙 늘어남 ㅎㅎ;
저렇게 각 버튼별 클릭리스너 달거나
하나로 클릭리스너 묶어서 GetID로 하는 법이 있던데 결국 그 줄이 그 줄인거 같더라구요 ;;;;;