讓我作序,我是Android新手。我一直在盡我的努力去研究無濟於事。我有下面的源代碼,我遇到了返回值的問題。setText不向TextView顯示值
我有eclipse上的代碼,它不會觸發任何錯誤。但是當我構建下面的代碼時,它會返回一個錯誤。在調試視圖中檢查值之後,我可以看到沒有綁定到TextView的正確值。
public class MyFirstActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
calculateResult(2012, 9, 29);
}
private void calculateResult(int year, int month, int day) {
long days = 0L;
int returning = 0;
java.util.Calendar cal = new java.util.GregorianCalendar(year, month-1, day);
long todayMI = new java.util.Date().getTime();
long calMI = cal.getTimeInMillis();
long millDiff = calMI - todayMI;
if (millDiff < 0) {
returning = 0;
} else {
days = millDiff/1000/60/60;
returning = (int) Math.ceil(days/24f);
}
TextView days_int_remaining = (TextView) findViewById(R.id.days_int_remaining);
days_int_remaining.setText(returning);
}
}
如果有幫助,這裏是我的佈局XML TextView的:
<TextView
android:id="@+id/days_int_remaining"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:shadowColor="#5000"
android:shadowDx="4"
android:shadowDy="3"
android:shadowRadius="1"
android:textColor="#fff"
android:textSize="70dip"
android:textStyle="bold"
/>
這可能是一些簡單的我失蹤。任何幫助我進一步理解代碼的東西都會被讚賞!
謝謝!這工作!我感謝幫助! – drukelly