0
我有一个SearchListActivity,它使用CustomSimpleCursor作为适配器。在这种CustomSimpleCursor我用很多代码的操作,原因在于SearchListActivity的表现已经到了bacause其中它滚动让ListviewActivity性能更流畅android
时挂起的水平SearchListActivity有
- 三ImageView的,其中,一-animates上滚动
- 13 TextView的
请帮助我,如何改变SearchListActivity,使性能提高
CustomSimpleCursor.java
public class CustomSimpleCursor extends SimpleCursorAdapter{
Typeface font;
TextView txtDaysRemainigValue,txtTurnsAge;
@SuppressWarnings("deprecation")
public CustomSimpleCursor(Context context, int layout, Cursor c,
String[] from, int[] to) {
super(context, layout, c, from, to);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
super.bindView(view, context, cursor);
String todayBD = null;
//Zodiac icon
try {
ImageView thumbZodiacIcon = (ImageView) view.findViewById(R.id.ImageView01);
InputStream bitmap = context.getResources().getAssets().open(cursor.getString(cursor.getColumnIndexOrThrow(BirthdayProvider.ZODIAC_ICON)));
Bitmap bit = BitmapFactory.decodeStream(bitmap);
thumbZodiacIcon.setImageBitmap(bit);
} catch (Exception e1) {
e1.printStackTrace();
}
// Event icon
try {
ImageView thumbEventIcon = (ImageView) view.findViewById(R.id.ImageView02);
InputStream bitmap = context.getResources().getAssets().open(cursor.getString(cursor.getColumnIndexOrThrow(BirthdayProvider.EVENT_ICON)));
Bitmap bit = BitmapFactory.decodeStream(bitmap);
thumbEventIcon.setImageBitmap(bit);
} catch (Exception e1) {
e1.printStackTrace();
}
//Contact photo
try {
ImageView thumbContact = (ImageView) view.findViewById(R.id.list_image);
byte bitmapData[]=cursor.getBlob(cursor.getColumnIndex(BirthdayProvider.PHOTO));
Bitmap bit = BitmapFactory.decodeByteArray(bitmapData, 0, bitmapData.length);
thumbContact.setImageBitmap(bit);
Animation localAnimation = AnimationUtils.loadAnimation(context,R.anim.fadein_image);
thumbContact.startAnimation(localAnimation);
} catch (Exception e1) {
e1.printStackTrace();
}
//Days remaining for BD
txtDaysRemainigValue=(TextView)view.findViewById(R.id.txtview_days_left);
String year=cursor.getString(cursor.getColumnIndex(BirthdayProvider.EVENT_YEAR));
String month=cursor.getString(cursor.getColumnIndex(BirthdayProvider.EVENT_MONTH));
String date=cursor.getString(cursor.getColumnIndex(BirthdayProvider.EVENT_DATE));
String remainingDays=BirthdayCalculation.getDaysRemainingForNextBirthDay(year, month, date);
Calendar today=Calendar.getInstance();
int CMonth=(today.get(Calendar.MONDAY)+1);
int CDate=(today.get(Calendar.DAY_OF_MONTH));
txtDaysRemainigValue.setTextColor(Color.parseColor("#990000"));
txtDaysRemainigValue.setTextSize(TypedValue.COMPLEX_UNIT_SP, 27);
//checking whether the BD is on TODAY
if (remainingDays.equals("1") && (CDate==Integer.parseInt(date) && (CMonth)==Integer.parseInt(month))) {
Log.v("else if executed","else if executed");
Log.v("Remainin Days",remainingDays+" = Custom month"+cursor.getString(cursor.getColumnIndex(BirthdayProvider.NAME))+"="+(CMonth)+"="+month);
Log.v("Remainin Days",remainingDays+" = Custom date"+ cursor.getString(cursor.getColumnIndex(BirthdayProvider.NAME))+"="+CDate+"="+date);
txtDaysRemainigValue.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
txtDaysRemainigValue.setTextColor(Color.parseColor("#00CC33"));
remainingDays="today".toLowerCase();
}
//checking whether the BD is on TOMORROW
else if (remainingDays.equals("1")) {
Log.v("Remainin Days",remainingDays+" = Custom month"+cursor.getString(cursor.getColumnIndex(BirthdayProvider.NAME))+"="+(CMonth)+"="+month);
Log.v("Remainin Days",remainingDays+" = Custom date"+ cursor.getString(cursor.getColumnIndex(BirthdayProvider.NAME))+"="+CDate+"="+date);
txtDaysRemainigValue.setTextSize(TypedValue.COMPLEX_UNIT_SP, 17);
txtDaysRemainigValue.setTextColor(Color.parseColor("#FFFF00"));
remainingDays="tomorrow".toLowerCase();
}
//checking how many days remaining BD
else{
remainingDays=BirthdayCalculation.getDaysRemainingForNextBirthDay(year, month, date);
txtDaysRemainigValue.setTextSize(TypedValue.COMPLEX_UNIT_SP, 27);
txtDaysRemainigValue.setTextColor(Color.parseColor("#990000"));
}
txtDaysRemainigValue=(TextView)view.findViewById(R.id.txtview_days_left);
font=Typeface.createFromAsset(context.getAssets(), "DS_DIGIB.ttf");
txtDaysRemainigValue.setTypeface(font);
txtDaysRemainigValue.setText(remainingDays);
//Turns age
txtTurnsAge=(TextView)view.findViewById(R.id.txtview_turns);
String turnsAge=BirthdayCalculation.getAge(Integer.parseInt(year),Integer.parseInt(month),Integer.parseInt(date));
txtTurnsAge.setText(turnsAge);
//Event week
try {
TextView txtEventWeek=(TextView)view.findViewById(R.id.txtview_next_bd);
String eventWeek=BirthdayCalculation.getDayOfWeek(year, month, date);
font=Typeface.createFromAsset(context.getAssets(), "Comic Sans.ttf");
txtEventWeek.setTypeface(font);
txtEventWeek.setText(eventWeek);
} catch (Exception e) {
e.printStackTrace();
}
// Contact Name
TextView txtNumber=(TextView)view.findViewById(R.id.sub_title_contact_number);
font=Typeface.createFromAsset(context.getAssets(), "Roboto_Light.ttf");
txtNumber.setTypeface(font);
TextView txtBirtgDay=(TextView)view.findViewById(R.id.sub_title_birthdate);
font=Typeface.createFromAsset(context.getAssets(), "Roboto_Light.ttf");
txtBirtgDay.setTypeface(font);
TextView txtZodiac=(TextView)view.findViewById(R.id.TextView02);
font=Typeface.createFromAsset(context.getAssets(), "Roboto_Light.ttf");
txtZodiac.setTypeface(font);
TextView txtZodiacValue=(TextView)view.findViewById(R.id.txtview_zodiac);
font=Typeface.createFromAsset(context.getAssets(), "Comic Sans.ttf");
txtZodiacValue.setTypeface(font);
TextView txtNextBD=(TextView)view.findViewById(R.id.TextView01);
font=Typeface.createFromAsset(context.getAssets(), "Roboto_Light.ttf");
txtNextBD.setTypeface(font);
TextView txtTurnsAge=(TextView)view.findViewById(R.id.list_image_arrow);
font=Typeface.createFromAsset(context.getAssets(), "athletic.ttf");
txtTurnsAge.setTypeface(font);
TextView txtDayRemainig=(TextView)view.findViewById(R.id.TextView04);
font=Typeface.createFromAsset(context.getAssets(), "athletic.ttf");
txtDayRemainig.setTypeface(font);
TextView txtTurnsAgeValue=(TextView)view.findViewById(R.id.txtview_turns);
font=Typeface.createFromAsset(context.getAssets(), "DS_DIGIB.ttf");
txtTurnsAgeValue.setTypeface(font);
}
}
你应该使用[Picasso](http://square.github.io/picasso)库在后台线程中延迟加载图像并缓存它们。 – corsair992