리스트뷰 아이템마다 프로그래스바가있고 버튼이 있어요 go버튼을 누르면 프로그래스바가 한단계 전진하는 그런 형태를 만들고싶은데 전진은되는데! 앱을껐다키거나 아니면 다른 액티비티를 갔다오기만해도 다시 프로그래스바가 초기화되요... 저는 진행해놓은 프로그래스바 ui상태를 저장하고싶어서 SharedPreference를 사용했는데..
상태저장이안되요 ㅠㅠ
public class DBAdapter3 extends CursorAdapter {
private SharedPreferences pref;
private SharedPreferences.Editor editor;
public DBAdapter3(Context context, Cursor c) {
super(context, c);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
final ProgressBar progressbar =(ProgressBar)view.findViewById(R.id.progressbar);
pref = context.getSharedPreferences("Pref", Activity.MODE_PRIVATE);
editor = pref.edit(); // 에디터를 받아옵니다.
//불러온당
Log.e("확인", "###########버튼문제확인##############");
progressbar.setProgress(pref.getInt("progressbar", 0));
progressbar.setProgress(pref.getInt("progressbar2",0));
progressbar.setProgress(pref.getInt("progressbar3",0));
progressbar.setProgress(pref.getInt("progressbar4",0));
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"));
btn_go.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try{
Log.d("확인", "###########버튼문제확인##############");
if (num == 4) {
progressbar.incrementProgressBy((int) 100 / 4);
editor.putInt("progressbar", progressbar.getProgress());
editor.apply();
} else if (num == 3) {
progressbar.incrementProgressBy(34);
editor.putInt("progressbar2", progressbar.getProgress());
editor.apply();
} else if (num == 2) {
progressbar.incrementProgressBy((int) 100 / 2);
editor.putInt("progressbar3", progressbar.getProgress());
editor.apply();
} else {
progressbar.incrementProgressBy(100);
editor.putInt("progressbar4", progressbar.getProgress());
editor.apply();
}
//editor.apply();
// progressbar.setProgress(pref.getInt("progressbar", 0));
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();
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(R.layout.progresslisttest, parent, false);
return v;
}
}