۱۳۹۴/۰۴/۲۷, ۱۱:۲۸ ب.ظ
سلام خدمت آدمین بقیه اساتید من این لیست اکتیویتی رو ساختم اما تو ساخت قسمت جستجو اشکال دارم یعنی نمیتونم آداپتر رو فیلتر کنم.این کدشه ممنون میشم کمک کنید. این که کل اکتیویته
کد پیاچپی:
public ListView lv;
public Globalsd global = new Globalsd();
public int Subjects_total_number;
public String[] Subjects;
SharedPreferences full;
EditText search;
public class MyAdapter extends ArrayAdapter<String> {
public MyAdapter(Context context, int resource, int textViewResourceId,
String[] strings) {
super(context, resource, textViewResourceId, strings);
// TODO Auto-generated constructor stub
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.list_item_subjectsd1, parent,
false);
String[] items = Subjects;
TextView tv = (TextView) row.findViewById(R.id.textView1);
tv.setText(items[position]);
Animation animation = AnimationUtils.loadAnimation(getContext(),
R.anim.slide_in_right);
row.startAnimation(animation);
return row;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
screnpref();
setContentView(R.layout.a_drog1);
search = (EditText) findViewById(R.id.edtsearchd1);
Subjects_total_number = global.Subjects_total_numberd;
Subjects = new String[Subjects_total_number];
for (int x = 1; x < Subjects_total_number + 1; x = x + 1) {
String this_subject = "subject_" + String.valueOf(x);
int resID = getResources().getIdentifier(this_subject, "string",
getPackageName());
Subjects[x - 1] = getResources().getString(resID);
}
setListAdapter(new MyAdapter(this, android.R.layout.simple_list_item_1,
R.id.textView1, Subjects));
lv = getListView();
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, final View view,
int position, long id) {
Intent i = new Intent(getApplicationContext(), Secendd1.class);
String Subject_number = String.valueOf(position + 1);
i.putExtra("subject_number", Subject_number);
startActivity(i);
}
});
search.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
[color=#FF0000] //this line:
//how i can filter this adapter
//این قسمت من اشکال دارم[/color]
((ArrayAdapter<String>) this.MyAdapter).getFilter().filter(s);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
}