안드로이드 변수 공유 문제 오류좀 봐주세요..
조회수 1635회
제가 리스트뷰별로 막대 프로그래스바와 go 버튼이 있는데요 go 버튼이 눌리면 체크박스 총 4개중 선택된 갯수를 받는 변수가 count인데 100/count 를 해서 프로그래스바를 진행시키는거예요
근데 만약 count가 리스트뷰 아이템별로 4/3/4 이렇게 있으면 세번째 리스트뷰 4가 맨앞에 있는 4를 go버튼을 누를때 값이 같이 따라가는데...그니까 count숫자가 같으면 그 단계를 다 따라가버려요!!!!!!!안따라가고...각 아이템별로 독립적으로 하고싶은데 ㅠㅠ 이걸 어케 변경해야하나요... 뭐가문제일까요
@Override
public void bindView(View view, Context context, Cursor cursor) {
final ProgressBar progressbar =(ProgressBar)view.findViewById(R.id.progressbar);
final TextView tx_count =(TextView)view.findViewById(R.id.checkcount);
final Button btn_go =(Button)view.findViewById(R.id.progressgo);
final Button btn_end =(Button)view.findViewById(R.id.progressend);
final int num =cursor.getInt(cursor.getColumnIndex("count"));
int position = cursor.getInt(cursor.getColumnIndex("_id"));
pref = PreferenceManager.getDefaultSharedPreferences(context);
editor = pref.edit(); // 에디터를 받아옵니다.
//불러온당
Log.e("확인", "###########버튼문제확인##############");
//int _id = cursor.getInt(cursor.getColumnIndex("_id"));
do {
try {
if (num == 4) {
progressbar.setProgress(pref.getInt("progressbar", 0));
} else if (num == 3) {
progressbar.setProgress(pref.getInt("progressbar2", 0));
} else if (num == 2) {
progressbar.setProgress(pref.getInt("progressbar3", 0));
} else {
progressbar.setProgress(pref.getInt("progressbar4", 0));
}
} catch (Exception e) {
e.printStackTrace();
}
}
while (cursor.moveToNext());
btn_go.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try{
//id1.setTag(position);
Log.d("확인", "###########버튼문제확인##############");
if (num == 4) {
progressbar.incrementProgressBy((int) 100 / 4);
editor.putInt("progressbar", progressbar.getProgress()).apply();
//editor.apply();
//progressbar.setProgress(pref.getInt("progressbar", 0));
} else if (num == 3) {
progressbar.incrementProgressBy(34);
editor.putInt("progressbar2", progressbar.getProgress()).apply();
//editor.apply();
//progressbar.setProgress(pref.getInt("progressbar2", 0));
} else if (num == 2) {
progressbar.incrementProgressBy((int) 100 / 2);
editor.putInt("progressbar3", progressbar.getProgress()).apply();
// editor.apply();
//progressbar.setProgress(pref.getInt("progressbar3", 0));
} else {
progressbar.incrementProgressBy(100);
editor.putInt("progressbar4", progressbar.getProgress()).apply();
editor.apply();
// progressbar.setProgress(pref.getInt("progressbar4", 0));
}
//editor.apply();
if(progressbar.getMax() == 100){
Toast.makeText(view.getContext(), "합격을 축하드립니다 :)",
Toast.LENGTH_SHORT).show();}
else{
Toast.makeText(view.getContext(), "진행이 종료되었습니다.",
Toast.LENGTH_SHORT).show();
}
}catch(Exception e){
e.printStackTrace();
}
}
});
btn_end.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
onContentChanged();
}
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력