I have the following code in Main.java :
public class Main extends Activity implements AdapterView.OnItemClickListener,OnClickListener
{ private ListAdapter adapter;
int complete;
ProgressBar progCompleted;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mListView = (ListView) findViewById(R.id.list);
adapter = new MyAdapter(this, R.layout.row, objects);
mListView.setAdapter(adapter);
mListView.setOnItemClickListener(this);
/*
* Complete rate
*/
this.complete += (int) getNumberCompleted();
this.progCompleted = (ProgressBar) findViewById(R.id.ProgBar_completed);
this.progCompleted.setMax(100);
this.progCompleted.setProgress(complete);
.......
}
And in MyAdapter.java :
public class MyAdapter extends ArrayAdapter<Task> {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
rowHolder myHolder= new rowHolder();
final int mposition = position;
View v = convertView;
if (v == null) {
v = mInflater.inflate(R.layout.row, null);
myHolder.check_button = (CheckBox) v.findViewById(R.id.CheckButton);
if(myHolder.check_button != null){
myHolder.check_button.setChecked(t.isCompleted());
OnClickListener l =new OnClickListener() {
@Override
public void onClick(View v) {
CheckBox cb = (CheckBox) v;
if (cb.isChecked())
{
some task...
}
}
};
myHolder.check_button.setOnClickListener(l);
}
}
return v;
}
So basiclly what I want is to be able to update the progressbar status when I click the CheckBox in the ListView .
The easiest way is to create method on your activity which will change your progress bar. As you sent to your adapter activity – call this method with parameter of new value for progress bar.
This method on Main activity.
Create constructor for your adapter with parameter Main mainActivity.
And then call in your adapter this method
mainActivity.setProgress(35);(depends from your logic – replace your “some task…” code ).Hope, this will help you.
With best regards,
Psycho