カスタムリストの行に 、、をListActivity
持つを作成しようとしています。CheckBox
TextView
EditText
ユーザーの入力を取得し、その行が選択されたEditText
ときにその値をデータベースに保存する必要があります。が選択されていないCheckBox
場合、は無効になります。後者はできますが、の値を保持してデータベースに保存することはできません。CheckBox
EditText
EditText
現在、何かを入力してEditText
戻るボタンを押してキーパッドを最小化するEditText
と、以前の値に戻ります。
ListView
カスタムを表示し、チェックボックスを選択および選択解除するために、今まで以下をコーディングしました。私はちょうどそのEditText
部分で私を助ける必要があります.
EditExepense.Java
package h.pkg.main;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.RadioGroup.OnCheckedChangeListener;
public class EditExpense extends ListActivity {
int eid, tid, mid;
String etyp,amount;
float eamt;
DBAdapter db;
ArrayList<Integer> memmid = new ArrayList<Integer>();
ArrayList<String> memname = new ArrayList<String>();
ArrayList<Float> memcexp = new ArrayList<Float>();
List<Model> list = new ArrayList<Model>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button Save = (Button)findViewById(R.id.Save);
//ListView l1= (ListView)findViewById(R.id.listView1);
setContentView(R.layout.eexp);
Bundle idata = getIntent().getExtras();
db = new DBAdapter(this);
if (idata !=null)
{
eid=idata.getInt("EID");
tid=idata.getInt("TID");
etyp=idata.getString("ETYP");
eamt=idata.getFloat("EXAMT");
amount = "" + eamt;
}
try {
db.open();
Cursor c = db.getAllmem(tid);
float nofm = (float)(c.getCount());
float evenshareamt = eamt/nofm;
db.close();
if (c != null ) {
if (c.moveToFirst()) {
do {
String MN = c.getString(c.getColumnIndex("NAME"));
mid = c.getInt(c.getColumnIndex("MID"));
String ceamts = String.valueOf(evenshareamt);
list.add(get(MN,ceamts,true));
memname.add(MN);
memmid.add(mid);
memcexp.add(evenshareamt);
} while (c.moveToNext());
}
}
c.close();
} finally {
}
ArrayAdapter<Model> adapter = new InteractiveArrayAdapter(this,list);
setListAdapter(adapter);
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radioGroup1);
RadioButton rbs = (RadioButton) findViewById(R.id.Shared);
RadioButton rbc = (RadioButton) findViewById(R.id.Custom);
radioGroup.setOnCheckedChangeListener( new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
RadioButton rbs = (RadioButton) findViewById(R.id.Shared);
if (rbs.isChecked()) {
//DisplayToast("Option 1 checked!");
} else {
//DisplayToast("Option 2 checked!");
}
}
});
}
public void expUpdate(View V) {
setResult(RESULT_OK);
finish();
}
private Model get(String memn, String ceam, boolean sel) {
return new Model(memn,ceam,sel);
}
}
InteractiveArrayAdapter.Java
package h.pkg.main;
import java.util.List;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;
public class InteractiveArrayAdapter extends ArrayAdapter<Model> {
private final List<Model> list;
private final Activity context;
public InteractiveArrayAdapter(Activity context, List<Model> list) {
super(context, R.layout.listview, list);
this.context = context;
this.list = list;
}
static class ViewHolder {
protected TextView memnames;
protected EditText ceamount;
protected CheckBox checkbox;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.listview, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.memnames = (TextView) view.findViewById(R.id.memname1);
viewHolder.ceamount = (EditText) view.findViewById(R.id.expamt1);
viewHolder.checkbox = (CheckBox) view.findViewById(R.id.chkbox1);
viewHolder.checkbox.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
Model elementc = (Model) viewHolder.checkbox.getTag();
elementc.setSelected(buttonView.isChecked());
boolean edenable = buttonView.isChecked();
if(edenable)
{
viewHolder.ceamount.setEnabled(true);
} else {
viewHolder.ceamount.setText("");
viewHolder.ceamount.setEnabled(false);
}
}
});
view.setTag(viewHolder);
viewHolder.checkbox.setTag(list.get(position));
} else {
view = convertView;
((ViewHolder) view.getTag()).checkbox.setTag(list.get(position));
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.memnames.setText(list.get(position).getName());
holder.ceamount.setText(list.get(position).getCeamt());
holder.checkbox.setChecked(list.get(position).isSelected());
return view;
}
}
モデル.Java
package h.pkg.main;
public class Model {
private String name;
private String ceexpamt;
private boolean selected;
public Model(String name, String ceexpamt, boolean selected) {
this.name = name;
this.ceexpamt = ceexpamt;
this.selected = selected;
}
public String getName() {
return name;
}
public String getCeamt() {
return ceexpamt;
}
public void setName(String name) {
this.name = name;
}
public void setCeamt(String ceamt) {
this.ceexpamt = ceamt;
}
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
public void enableEditText()
{
}
}