목록에서 프로그래밍 방식으로 생성 된 버튼의 스크롤 가능한 목록 (열을 보자)을 생성하는 활동은 sqlite 테이블을 읽은 결과이며 내 문제는 목록이 점점 커지고 있습니다 (버튼 수가 많아짐) 화면의 초기 그림이 느려지는 중입니다 (현재 50 개의 단추를 사용하여 3 초가 걸립니다). 그래서이 문제에 대한 해결책을 찾고 있습니다.프로그래밍 방식으로 생성 된 많은 버튼의 속도가 빨라짐
처음에는 스레드 (runnable, handler 또는 무엇이 가장 좋았는지)를 사용하여 생각했습니다. For 내부에 새 스레드를 만드는 것이 목록을 반복하지만 작동하지 않습니다. (또는 적어도 나는 할 수 없습니다.) 내 질문은 다음입니다 :
스크롤 버튼의 큰 세트를 만드는 가장 좋은 방법입니다 목록 <>에서 시작하므로 사용자가 화면에 액세스 할 때 그러한 지연을하지 않습니다.
페이지 매김은 옵션 일 수 있지만 다른 가능성을 먼저 알고 마지막 리소스로 남겨 두는 것이 좋습니다.
감사합니다. 아래 코드는 내 코드입니다.
public static void createButtons(LinearLayout llContainer,
List<TestType> TestTypes, List<Test> Tests,
int buttonFontSize) {
Context oContext = llContainer.getContext();
String strTheme = TMAppearance.getThemeFromPreferences(oContext);
testMe = ((ApplicationConfiguration)oContext.getApplicationContext());
int callerActivity = TestTypes!=null ? 2 : 1;
if (TestTypes!=null || Tests!=null) {
int lCols = strTheme.equals(testMe.theme_vivid) ? 1 : 2;
//int sourceElementIndex = 0;
int originListSize = calculateOriginalListSize(callerActivity, TestTypes, Tests);
int lRows = (int) Math.ceil((double)originListSize/lCols);
List<String> aStartColors = TMUtils_ThemeVivid.generateStartColorArray(lRows, oContext);
List<String> aEndColors = TMUtils_ThemeVivid.generateEndColorArray(lRows, oContext);
for (i = 0; i < lRows; i++) {
LinearLayout outerButtonLayout = generateOuterButtonLayout(oContext);
for (j = 0; j < lCols; j++) {
final Thread r = new Thread() {
public void run() {
LinearLayout innerButtonLayout = generateInnerButtonLayout(oContext);
outerButtonLayout.addView(innerButtonLayout, j);
if (sourceElementIndex<originListSize){
final TMButton oButton = new TMButton(oContext);
if (callerActivity==1) { //testMenu
setTestMenuButtonSettings(oButton, sourceElementIndex, Tests);
} else {
if (callerActivity==2) { //testTypeMenu
setTestTypeMenuButtonSettings(oButton, sourceElementIndex, TestTypes);
}
}
if (strTheme.equals(testMe.theme_vivid)){
oButton.fontSize = buttonFontSize;
oButton.gradientStartColor = aStartColors.get(i);
oButton.gradientEndColor = aEndColors.get(i);
}else{
if (strTheme.equals(testMe.theme_purple)){
oButton.gradientStartColor = testMe.btnStartColor_purple;
oButton.gradientEndColor = testMe.btnEndColor_purple;
}
}
configureButton(oButton, callerActivity);
oButton.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Context oContext = v.getContext();
TMButton oButton = (TMButton) v;
int callerActivity = Integer.valueOf(v.getTag().toString().split("@")[0]);
String sourceId = String.valueOf(v.getTag().toString().split("@")[1]);
if(event.getAction() == MotionEvent.ACTION_DOWN) { //pressed
setButtonPressed(oButton);
TMSound.playButtonSound(oContext);
} else if (event.getAction() == MotionEvent.ACTION_UP) { //released
setButtonReleased(oButton);
startTargetActivity(callerActivity, sourceId, oContext);
}
return true;
}
});
TMAppearance.doButtonAnimation(oContext, oButton, i);
innerButtonLayout.addView(oButton);
sourceElementIndex++;
}
}
};
r.run();
}
llContainer.addView(outerButtonLayout);
}
}
}
에서보다 구현 쉽게
onClick
이벤트가'ListView' 또는 반대하는'RecycleView' 사용에 대한 뭔가가 있다는 것이다? 사용자 정의 레이아웃을 사용하면 유연성이 매우 높습니다. – BarnsBarns52에 답장을 보내 주셔서 대단히 감사합니다. 물론 ListView에 반대하지는 않았습니다. 프로그래밍 방식으로 버튼이 생성되기 때문에 사실 ListView를 구현하는 방법을 조사하고 있습니다. 동적으로 생성 된 ListView를 문제없이 사용할 수 있다고 생각합니까? –
ListView (nostalgia ?;-))를 좋아하지만 RecyclerView는 ListView와 비교하여 더 나은 성능을 제공합니다. 스크롤 할 때. – 0X0nosugar