simplecursoradapter を拡張する customlistview を検索したいです。多くの方法を試しましたが、取得できません。ここに私のコードがあります。前もって感謝します。1.検索機能付きクラス
public class Alertadditem extends Activity {
private CustomContacts custAdapter;
Editext edt;
ListView listview;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alertdesignlist);
String[] from = new String[] { Contactsnew.CONTENT };
int[] to = new int[] { R.id.content123};
custAdapter = new CustomContacts(this,
R.layout.activity_contactitem, null, from, to);
listview.setAdapter(custAdapter);
listview.setTextFilterEnabled(true);
edt.addTextChangedListener(new TextWatcher(){
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
//setUpSearchList();
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
dataAdapter.getFilter().filter(s);
}
});
2.カスタムアダプター
public class CustomContacts extends SimpleCursorAdapter {
public CustomContacts(Context context, int layout, Cursor c, String[] from,
int[] to) {
super(context, layout, c, from, to);
// TODO Auto-generated constructor stub
}
public CharSequence convertToString(Cursor cursor) {
return cursor.getString(cursor.getColumnIndex(Contactsnew.CONTENT));
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//get reference to the row
View view = super.getView(position, convertView, parent);
//check for odd or even to set alternate colors to the row background
if(position % 2 == 0){
view.setBackgroundColor(0xFFC1E7FF);
}
else {
view.setBackgroundColor(0xFF6495ED);
}
final TextView ttext = (TextView)view.findViewById(R.id.finaltext);
final LinearLayout ll = (LinearLayout) view.findViewById(R.id.ll11);
final TextView tcontent = (TextView)view.findViewById(R.id.content123);
final CheckBox check = (CheckBox)view.findViewById(R.id.itemcheck);
check.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if(check.isChecked()){
tcontent.setPaintFlags(tcontent.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
ttext.setVisibility(v.VISIBLE);
ll.setVisibility(v.VISIBLE);
}else{
tcontent.setPaintFlags(tcontent.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
ttext.setVisibility(v.GONE);
ll.setVisibility(LinearLayout.GONE);
}
}
});
return view;
}
}