我是Android的新手,制作一个应用程序,显示每10秒钟更新一次的电池温度......请帮帮我
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// setContentView(R.layout.activity_blue_tooth);
LinearLayout big = new LinearLayout(this);
big.setOrientation(LinearLayout.VERTICAL);
LinearLayout small[]= new LinearLayout[5];
for(int i=0; i<5; i++)
{
small[i]= new LinearLayout(this);
small[i].setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams linearparams1 = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
temp = new TextView(this);
small[i].addView(temp);
volt= new TextView(this);
small[i].addView(volt);
big.addView(small[i]);
}
setContentView(big);
this.registerReceiver(this.mBatInfoReceiver,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
}
private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent intent) {
// TODO Auto-generated method stub
int temperature = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0);
int voltage= intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE,0);
temp.setText("Temperature="+String.valueOf(temperature) + "%");
volt.setText(" " +"Voltage="+String.valueOf(voltage) + "%");
}
};
我正在获得电池温度和电压,但我无法每10秒更新一次