mirror of
https://github.com/balkian/Carrousel-Android.git
synced 2024-12-22 21:18:13 +00:00
I9: Checkboxes y Adapter propio
This commit is contained in:
parent
4bb85fb0de
commit
ee90d55080
6
res/layout/list_item.xml
Normal file
6
res/layout/list_item.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<TextView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
</TextView>
|
@ -6,12 +6,20 @@ import android.app.Activity;
|
|||||||
import android.app.ListActivity;
|
import android.app.ListActivity;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
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 {
|
public class Configuration extends ListActivity {
|
||||||
private Results mResults;
|
private Results mResults;
|
||||||
@ -57,8 +65,82 @@ public class Configuration extends ListActivity {
|
|||||||
ArrayList<Match> matches = mResults.getMatches();
|
ArrayList<Match> matches = mResults.getMatches();
|
||||||
Match[] ms = new Match[matches.size()];
|
Match[] ms = new Match[matches.size()];
|
||||||
matches.toArray(ms);
|
matches.toArray(ms);
|
||||||
ArrayAdapter<Match> adapter = new ArrayAdapter<Match>(this, R.layout.list_item, ms);
|
MatchAdapter adapter = new MatchAdapter(ms);
|
||||||
setListAdapter(adapter);
|
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.
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user