roger
unread,Sep 2, 2010, 10:11:29 PM9/2/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to 日本Androidの会
皆さん こんにちは
rogerです、最近Androidアプリ開発していますが、
ListViewの使い方がちょっと難しい感じています。
今回実現したいのは、こんな感じ:
---------------------------------------------
String1.... ☆
String2... ×
---------------------------------------------
String3.... ☆
String4... ×
---------------------------------------------
String5.... ☆
String6... ×
---------------------------------------------
ListViewで自定義ArrayAdapterをセットして表示できますが、各項目について「☆」と「×」ボタンを押すと、DBに更新(削除)し、
ListViewも更新(削除)したい。
DB更新操作は問題解決しましたが、ListViewを更新、削除の方法を見つかりません。ご存知の方が居れば教えでもらいませんが?
以下は部分ソースです:
public class WordsAdapter extends ArrayAdapter{
private LayoutInflater mInflater;
private ArrayList items;
private Boolean isHistoryTab = false;
/**
* 該当tabを履歴tabを設定
* @param isHistoryTab
*/
public void setIsHistoryTab(Boolean isHistoryTab) {
this.isHistoryTab = isHistoryTab;
}
public WordsAdapter(Context context,int textViewResourceId,List
objects) {
super(context,textViewResourceId, objects);
mInflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.items = (ArrayList) objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
// ビューを受け取る
if (convertView == null) {
// 受け取ったビューがnullなら新しくビューを生成
convertView = mInflater.inflate(R.layout.list_at, null);
}
final View a = convertView;
// 表示すべきデータの取得
final DbTableBean item = (DbTableBean)items.get(position);
if (item != null) {
TextView oWords = (TextView) convertView.findViewById(R.id.oWords);
final CheckBox cStar = (CheckBox)
convertView.findViewById(R.id.star);
TextView tWords = (TextView) convertView.findViewById(R.id.tWords);
Button bDel = (Button) convertView.findViewById(R.id.bDelete);
//「☆」eventを設定
cStar.setOnCheckedChangeListener(new OnCheckedChangeListener(){
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
//starの状態を変更処理
DataDao dao = new DataDao(a.getContext());
DbTableBean newBean= new DbTableBean();
newBean = item;
int checked = 0;
if(cStar.isChecked()){
checked = 1;
}
newBean.setStarFlag(checked);
//db更新
dao.saveData(newBean);
}
});
//「×」eventを設定
bDel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//ここで処理追加できないですか?
// Items.remove(item); を使いましたが、無理みた
い!
}
});
oWords.setText(item.getOriginalWords());
int flg = item.getStarFlag();
if(flg == 0){
cStar.setChecked(false);
}else{
cStar.setChecked(true);
}
tWords.setText(item.getTranslationWords());
}
return convertView;
}
}
以上、よろしくお願い致します。