diff --git a/res/layout/list_item.xml b/res/layout/list_item.xml new file mode 100644 index 0000000..9f45177 --- /dev/null +++ b/res/layout/list_item.xml @@ -0,0 +1,6 @@ + + + diff --git a/src/com/onirica/carrousel/Configuration.java b/src/com/onirica/carrousel/Configuration.java index 5e91416..78b5100 100644 --- a/src/com/onirica/carrousel/Configuration.java +++ b/src/com/onirica/carrousel/Configuration.java @@ -6,12 +6,20 @@ import android.app.Activity; import android.app.ListActivity; import android.app.ProgressDialog; import android.content.ComponentName; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.IBinder; +import android.view.View; +import android.view.ViewGroup; import android.widget.ArrayAdapter; +import android.widget.BaseAdapter; +import android.widget.CheckBox; +import android.widget.CompoundButton; +import android.widget.LinearLayout; +import android.widget.TextView; public class Configuration extends ListActivity { private Results mResults; @@ -57,8 +65,82 @@ public class Configuration extends ListActivity { ArrayList matches = mResults.getMatches(); Match[] ms = new Match[matches.size()]; matches.toArray(ms); - ArrayAdapter adapter = new ArrayAdapter(this, R.layout.list_item, ms); - setListAdapter(adapter); - + MatchAdapter adapter = new MatchAdapter(ms); + setListAdapter(adapter); + } + + private class MatchView extends LinearLayout { + private TextView mTv; + private CheckBox mCb; + private CompoundButton.OnCheckedChangeListener mListener = null; + + public MatchView(Context context, String text) { + super(context); + this.setOrientation(HORIZONTAL); + mTv = new TextView(context); + mTv.setText(text); + mCb = new CheckBox(context); + mCb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (mListener != null) { + mListener.onCheckedChanged(buttonView, isChecked); } + } + }); + + this.addView(mTv, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1)); + this.addView(mCb, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0)); + } + + public void setText(String text) { + mTv.setText(text); + } + + public void setOnMatchCheckedChanged(CompoundButton.OnCheckedChangeListener listener) { + mListener = listener; + } + } + private class MatchAdapter extends BaseAdapter { + private Match mMatches[]; + + public MatchAdapter(Match matches[]) { + super(); + mMatches = matches; + } + @Override + public int getCount() { + return mMatches.length; + } + + @Override + public Object getItem(int pos) { + return (Object)mMatches[pos]; + } + + @Override + public long getItemId(int pos) { + return pos; + } + public View getView(int pos, View convertView, ViewGroup parent) { + MatchView v; + if (convertView == null) { + v = new MatchView(parent.getContext(), mMatches[pos].toString()); + v.setOnMatchCheckedChanged(new OnMatchCheckedListener(pos)); + } else { + v = (MatchView)convertView; + v.setText(mMatches[pos].toString()); + } + return v; + } + private class OnMatchCheckedListener implements CompoundButton.OnCheckedChangeListener { + private int mPosition; + OnMatchCheckedListener(int position){ + mPosition = position; + } + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + // Do the real stuff here. + } + + } } } \ No newline at end of file