0
特定字母顯示視圖我有自定義適配器ListView和我創建使用矢量 我想只顯示包含字母「A」,例如該國的TextView。 和我找不到解決方案來做到這一點。包含ListView中
這是我的適配器和我怎樣努力去做
public class CountryAdapter extends BaseAdapter {
protected MainActivity main = new MainActivity();
private Context mContext;
protected Vector<Country> mVector;
protected SQLiteDatabase mDb;
Cursor cursor;
ImageView deleteIt;
View rowView;
public int pos;
public void setmContext(Context mContext) {
this.mContext = mContext;
}
public CountryAdapter(Context mContext) {
this.mContext = mContext;
mVector = new Vector<Country>();
CountryOpenHelper helper = new CountryOpenHelper(mContext);
mDb = helper.getWritableDatabase();
cursor = mDb.rawQuery("SELECT * FROM COUNTRIES", null);
if (cursor.getCount() > 0) {
cursor.moveToFirst();
}
do {
Country country = new Country();
country.setmCountryIndex(cursor.getInt(0));
country.setmCountryName(cursor.getString(2));
country.setmCountryTextSize(cursor.getInt(1));
country.setmCountryColor(cursor.getInt(3));
mVector.add(country);
for (int i = 0; i < cursor.getCount(); i++){
if (mVector.get(i).toString().contains("a") == false){
mVector.remove(i);
}
}
} while (cursor.moveToNext());
如果這裏需要的是在我的CountryAdapter我GetView方法多數民衆贊成在太:
public View getView(int position, View convertView, ViewGroup parent) {
TextView tv;
if(convertView == null){
tv = new TextView(mContext);
}else{
tv = (TextView) convertView;
}
this.pos = position;
tv.setText(mVector.get(position).getmCountryName());
tv.setTextColor(mVector.get(position).getmCountryColor());
tv.setTextSize(mVector.get(position).getmCountryTextSize());
return tv;
}
我改成了mVector.size();仍然沒有反應.. –