我有一個視圖,通過使用viewFlipper和onFling手勢來填充。當我扔屏幕填充下一個視圖時,需要2到3秒才能顯示下一個視圖。任何想法可能會發生什麼?這完全太慢了!用手勢填充viewFlipper的速度很慢
下面是我的一些代碼片段:
private void updateView() {
Log.i(DEBUG_TAG, "updateView");
// Preferences
// boolean to track view on ...toggle method to pass boolean into and display appropriate
mAdapter = new ForecastAdapter(mContext, R.layout.forecast_item, mWdm);
mListView = (ListView) findViewById(R.id.forecast_list);
mGestureDetector = new GestureDetector(new MyGestureDetector());
mForecastDetails = (RelativeLayout) findViewById(R.id.detail_view);
initIndicators();
if (mListView.getVisibility() == View.VISIBLE) {
displayForecastListView();
} else {
displayForecastDetailsView();
}
}
private void displayForecastDetailsView() {
mListView.setVisibility(View.GONE);
mForecastDetails.setVisibility(View.VISIBLE);
mMetric = mWdm.metric;
// Set the touch listener for the main view to be our custom gesture listener
//mainview.setOnTouchListener(new View.OnTouchListener() {
this.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (mGestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
});
mFlipper = (ExceptionCheckedViewFlipper) findViewById(R.id.details_flipper);
mNext = (ImageButton) findViewById(R.id.next_btn);
mNext.setImageBitmap(ACCUWX.applyFilter(
mContext, BitmapFactory.decodeResource(
mContext.getApplicationContext().getResources(), R.drawable.right_arrow)));
mPrevious = (ImageButton) findViewById(R.id.previous_btn);
mPrevious.setImageBitmap(ACCUWX.applyFilter(
mContext, BitmapFactory.decodeResource(
mContext.getApplicationContext().getResources(), R.drawable.left_arrow)));
mNext.setOnClickListener(this);
mPrevious.setOnClickListener(this);
populateDetailView(mIndex);
}
private void populateDetailView(int index) {
mForecastDayIndicator.setForecastIndex(index);
Log.i(DEBUG_TAG, "pouplateView");
TextView tv;
ImageView icon;
ImageView alarmIcon;
ImageView viewToggle;
ForecastModel fm;
boolean isEnabled = false;
Boolean isAlarm = false;
LinearLayout includes = (LinearLayout)mFlipper.getCurrentView();
viewToggle = (ImageView)includes.findViewById(R.id.view_toggle);
viewToggle.setOnClickListener(this);
LinearLayout ll = (LinearLayout)includes.findViewById(R.id.detail_container);
if(index >= 0 && index lessThan mWdm.forecast.size()) {
fm = mWdm.forecast.get(index);
// day/date
tv = (TextView)includes.findViewById(R.id.day_date);
tv.setText(fm.name + " " + fm.date);
// hi temp
tv = (TextView)includes.findViewById(R.id.hi_temp);
tv.setText(fm.high + DEG);
// lo temp
tv = (TextView)includes.findViewById(R.id.lo_temp);
tv.setText(fm.low + DEG);
// realfeel hi lo
tv = (TextView)includes.findViewById(R.id.realtemp);
tv.setText(fm.reelfeelhigh + DEG + "/" + fm.reelfeellow + DEG);
// day info
tv = (TextView)includes.findViewById(R.id.day);
tv.setText(mContext.getApplicationContext().getResources().getString(R.string.day).toUpperCase());
// day icon
icon = (ImageView)includes.findViewById(R.id.day_icon);
icon.setImageResource(ACCUWX.getDrawableId("icon_" + fm.iconCode));
// day shorttext
tv = (TextView)includes.findViewById(R.id.day_shorttext);
tv.setText(fm.shortText);
// night info
tv = (TextView)includes.findViewById(R.id.night);
tv.setText(mContext.getApplicationContext().getResources().getString(R.string.night).toUpperCase());
// night icon
icon = (ImageView)includes.findViewById(R.id.night_icon);
icon.setImageResource(ACCUWX.getDrawableId("icon_" + fm.nightCode));
// night shorttext
tv = (TextView)includes.findViewById(R.id.night_shorttext);
tv.setText(fm.nightText);
// headings
// precip
tv = (TextView)includes.findViewById(R.id.precip_title);
tv.setText(mContext.getApplicationContext().getResources().getString(R.string.precip).toUpperCase());
// day
tv = (TextView)includes.findViewById(R.id.day_title);
tv.setText(mContext.getApplicationContext().getResources().getString(R.string.day).toUpperCase());
// night
tv = (TextView)includes.findViewById(R.id.night_title);
tv.setText(mContext.getApplicationContext().getResources().getString(R.string.night).toUpperCase());
// wind
tv = (TextView)includes.findViewById(R.id.wind_title);
tv.setText(mContext.getApplicationContext().getResources().getString(R.string.wind).toUpperCase());
// Precip fields
String rainIceUnits = (mMetric == ACCUWX.Units.METRIC) ? mContext.getApplicationContext().getResources().getString(R.string.mm) : mContext.getApplicationContext().getResources().getString(R.string.inches);
String snowUnits = (mMetric == ACCUWX.Units.METRIC) ? mContext.getApplicationContext().getResources().getString(R.string.cm) : mContext.getApplicationContext().getResources().getString(R.string.inches);
String speedUnits = (mMetric == ACCUWX.Units.METRIC) ? mContext.getApplicationContext().getResources().getString(R.string.kph) : mContext.getApplicationContext().getResources().getString(R.string.mph);
// set text color to white if measurements other than 0, else gray out
// rain
isAlarm = Alarms.checkRainAlarms(mWdm, fm);
alarmIcon = (ImageView) includes.findViewById(R.id.rain_alarm_img);
if (isAlarm == true) alarmIcon.setVisibility(View.VISIBLE);
else alarmIcon.setVisibility(View.INVISIBLE);
isEnabled = !(checkForZero(fm.rain) && checkForZero(fm.nightRain));
tv = (TextView)findViewById(R.id.rain);
tv.setEnabled(isEnabled);
isEnabled = !checkForZero(fm.rain);
tv = (TextView)includes.findViewById(R.id.day_rain);
tv.setText(fm.rain + " " + rainIceUnits);
tv.setEnabled(isEnabled);
isEnabled = !checkForZero(fm.nightRain);
tv = (TextView)includes.findViewById(R.id.night_rain);
tv.setText(fm.nightRain + " " + rainIceUnits);
tv.setEnabled(isEnabled);
// snow
isAlarm = Alarms.checkSnowAlarms(mWdm, fm);
alarmIcon = (ImageView) includes.findViewById(R.id.snow_alarm_img);
if (isAlarm == true) alarmIcon.setVisibility(View.VISIBLE);
else alarmIcon.setVisibility(View.INVISIBLE);
isEnabled = !(checkForZero(fm.snow) && checkForZero(fm.nightSnow));
tv = (TextView)findViewById(R.id.snow);
tv.setEnabled(isEnabled);
isEnabled = !checkForZero(fm.snow);
tv = (TextView)includes.findViewById(R.id.day_snow);
tv.setText(fm.snow + " " + snowUnits);
tv.setEnabled(isEnabled);
isEnabled = !checkForZero(fm.nightSnow);
tv = (TextView)includes.findViewById(R.id.night_snow);
tv.setText(fm.nightSnow + " " + snowUnits);
tv.setEnabled(isEnabled);
// ice
isAlarm = Alarms.checkIceAlarms(mWdm, fm);
alarmIcon = (ImageView) includes.findViewById(R.id.ice_alarm_img);
if (isAlarm == true) alarmIcon.setVisibility(View.VISIBLE);
else alarmIcon.setVisibility(View.INVISIBLE);
isEnabled = !(checkForZero(fm.ice) && checkForZero(fm.nightIce));
tv = (TextView)findViewById(R.id.ice);
tv.setEnabled(isEnabled);
isEnabled = !checkForZero(fm.ice);
tv = (TextView)includes.findViewById(R.id.day_ice);
tv.setText(fm.ice + " " + rainIceUnits);
tv.setEnabled(isEnabled);
isEnabled = !checkForZero(fm.nightIce);
tv = (TextView)includes.findViewById(R.id.night_ice);
tv.setText(fm.nightIce + " " + rainIceUnits);
tv.setEnabled(isEnabled);
// Wind Data
isAlarm = Alarms.checkGustsAlarms(mWdm, fm);
alarmIcon = (ImageView) includes.findViewById(R.id.gusts_alarm_img);
if (isAlarm == true) alarmIcon.setVisibility(View.VISIBLE);
else alarmIcon.setVisibility(View.INVISIBLE);
isEnabled = !(checkForZero(fm.gust) && checkForZero(fm.nightGust));
tv = (TextView)findViewById(R.id.gusts);
tv.setEnabled(isEnabled);
isEnabled = !checkForZero(fm.gust);
tv = (TextView)includes.findViewById(R.id.day_gusts);
tv.setText(fm.gust + " " + speedUnits);
tv.setEnabled(isEnabled);
isEnabled = !checkForZero(fm.nightGust);
tv = (TextView)includes.findViewById(R.id.night_gusts);
tv.setText(fm.nightGust + " " + speedUnits);
tv.setEnabled(isEnabled);
// speed
isAlarm = Alarms.checkSpeedAlarms(mWdm, fm);
alarmIcon = (ImageView) includes.findViewById(R.id.speed_alarm_img);
if (isAlarm == true) alarmIcon.setVisibility(View.VISIBLE);
else alarmIcon.setVisibility(View.INVISIBLE);
isEnabled = !(checkForZero(fm.wind) && checkForZero(fm.nightWind));
tv = (TextView)findViewById(R.id.speed);
tv.setEnabled(isEnabled);
isEnabled = !checkForZero(fm.wind);
tv = (TextView)includes.findViewById(R.id.day_speed);
tv.setText(fm.wind + " " + speedUnits);
tv.setEnabled(isEnabled);
isEnabled = !checkForZero(fm.nightWind);
tv = (TextView)includes.findViewById(R.id.night_speed);
tv.setText(fm.nightWind + " " + speedUnits);
tv.setEnabled(isEnabled);
// tstorms
isAlarm = Alarms.checkTstormAlarms(mWdm, fm);
alarmIcon = (ImageView) includes.findViewById(R.id.tstorms_alarm_img);
if (isAlarm == true) alarmIcon.setVisibility(View.VISIBLE);
else alarmIcon.setVisibility(View.INVISIBLE);
isEnabled = !(checkForZero(fm.tstorm) && checkForZero(fm.nightTstorm));
tv = (TextView)findViewById(R.id.tstorms);
tv.setEnabled(isEnabled);
isEnabled = !checkForZero(fm.tstorm);
tv = (TextView)includes.findViewById(R.id.day_tstorms);
tv.setText(fm.tstorm + PERCENT);
tv.setEnabled(isEnabled);
isEnabled = !checkForZero(fm.nightTstorm);
tv = (TextView)includes.findViewById(R.id.night_tstorms);
tv.setText(fm.nightTstorm + PERCENT);
tv.setEnabled(isEnabled);
}
}
你在測試什麼設備? – FoamyGuy 2011-05-13 19:14:35
Nexus One 2.3.4 – taraloca 2011-05-13 19:27:40