Timer task TimerTask run cancel Android example
Update TextView from TimerTask, Handler, schedule, run, cancel TimerTask, Android example
public class TimerActivity extends Activity {
TimerTask mTimerTask;
final Handler handler = new Handler();
Timer t = new Timer();
TextView hTextView;
TableRow hTableRow;
Button hButton, hButtonStop;
private int nCounter = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
hTextView = (TextView)findViewById(R.id.idTextView);
hButton = (Button)findViewById(R.id.idButton);
hButton.setOnClickListener(mButtonStartListener);
hButtonStop = (Button)findViewById(R.id.idButtonStop);
hButtonStop.setOnClickListener(mButtonStopListener);
} // end onCreate
View.OnClickListener mButtonStartListener = new OnClickListener() {
public void onClick(View v) {
doTimerTask();
}
};
View.OnClickListener mButtonStopListener = new OnClickListener() {
public void onClick(View v) {
stopTask();
}
};
public void doTimerTask(){
mTimerTask = new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
nCounter++;
// update TextView
hTextView.setText("Timer: " + nCounter);
Log.d("TIMER", "TimerTask run");
}
});
}};
// public void schedule (TimerTask task, long delay, long period)
t.schedule(mTimerTask, 500, 3000); //
}
public void stopTask(){
if(mTimerTask!=null){
hTextView.setText("Timer canceled: " + nCounter);
Log.d("TIMER", "timer canceled");
mTimerTask.cancel();
}
}
}
396LW NO topic_id
AD
Další témata ....(Topics)
HTC Sensation 4G cena od 11 000 KCZ Kč (únor.2012)
Spokojenost uživatelů nadprůměrná.
HTC Sensation 4G je chytrý telefon s operačním systémem Android.
HTC Sensation 4G je (22.února2012) 10. nejpoužívanějším chytrým telefonem u programu Sky Map viz tabulka.
Výrobce HTC
Kompatibilní sítě GSM / GPRS / EDGE
850 900 1800 1900 MHz
UMTS / HSPA
850 1900 2100 nebo 900 1700 2100 MHz
HSDPA 14,4 Mbps
HSUPA 5.76 Mbps
První předvedení 19.května 2011
Zaváděcí cena US 199,99 dolarů
Nástupce HTC Sensation XE, HTC 4G Amaze
Rozměry 126.1 mm (4.96 v) H
65.4 mm 2,57 in) W
11.3 mm (0,44 in) D
Hmotnost 148 g
Operační systém Android 2.3.3 Gingerbread (upgrade až na 2.3.4),
HTC Sense 3.0 overlay
Procesor:
Dual-core CPU, 1.2 GHz Qualcomm MSM8260 Snapdragon, Sensation XE dual-core 1,5 GHz Qualcomm MSM8260 Snapdragon, Sensation XL jednoho jádra 1,5 GHz Qualcomm MSM8255 Snapdragon
GPU Qualcomm adreno 220, Sensation XL adreno 205
Paměť 768 MB RAM
4 GB (1 GB uživatelsky dostupných)
Paměť vyjmutelná: 8 GB microSD 2.0, podporuje až 32 GB
Baterie 1520 mAh vnitřní dobíjecí Li-ion vyměnitelné
Datové vstupy A-GPS, čidlo okolního osvětlení, digitální kompas, G-senzor, gyroskop, multi-touch kapacitní dotykový displej, snímač
Displej 4.3 v (110 mm) kapacitní S-LCD dotykový displej Gorilla skla s QHD (540 × 960) rozlišením na 256.15 PPI
Fotoaparát na zadní straně s 8 miliony pixelů (3264 x 2448) s automatickým ostřením a dvojitým LED bleskem a 1080p HD video záznamu @ 30 snímků / s, kohoutek k zaměření s digitálním zoomem
Fotoaparát na přední straně VGA pevné zaostření barevná kamera (0,3 megapixelů)
Kompatibilní média formáty audio AAC, AMR, OGG, M4A, MIDI, MP3, WAV, WMA
Video 1920 × 1080 (1080p HD) @ 30 snímků / s - 3GP, .3 G2, MP4, WMV, AVI, XVID
Vyzváněcí tóny a oznámení všechny kompatibilní audio formáty
Vibrace
Připojení 3.5 mm TRRS konektor, Bluetooth 3.0 s A2DP, FM přijímač (87,5 - 108 MHz) s RDS, Micro USB 2.0 (5-pin) port s Mobile High-Definition Link (MHL) pro USB nebo HDMI připojení, Wi-Fi 802.11b/g/n
Zdroj: wikipedia
HTC Sensation 4G photo pic image
Zdroj obrázku: wikipedia
Spokojenost uživatelů nadprůměrná.
HTC Sensation 4G je chytrý telefon s operačním systémem Android.
HTC Sensation 4G je (22.února2012) 10. nejpoužívanějším chytrým telefonem u programu Sky Map viz tabulka.
Výrobce HTC
Kompatibilní sítě GSM / GPRS / EDGE
850 900 1800 1900 MHz
UMTS / HSPA
850 1900 2100 nebo 900 1700 2100 MHz
HSDPA 14,4 Mbps
HSUPA 5.76 Mbps
První předvedení 19.května 2011
Zaváděcí cena US 199,99 dolarů
Nástupce HTC Sensation XE, HTC 4G Amaze
Rozměry 126.1 mm (4.96 v) H
65.4 mm 2,57 in) W
11.3 mm (0,44 in) D
Hmotnost 148 g
Operační systém Android 2.3.3 Gingerbread (upgrade až na 2.3.4),
HTC Sense 3.0 overlay
Procesor:
Dual-core CPU, 1.2 GHz Qualcomm MSM8260 Snapdragon, Sensation XE dual-core 1,5 GHz Qualcomm MSM8260 Snapdragon, Sensation XL jednoho jádra 1,5 GHz Qualcomm MSM8255 Snapdragon
GPU Qualcomm adreno 220, Sensation XL adreno 205
Paměť 768 MB RAM
4 GB (1 GB uživatelsky dostupných)
Paměť vyjmutelná: 8 GB microSD 2.0, podporuje až 32 GB
Baterie 1520 mAh vnitřní dobíjecí Li-ion vyměnitelné
Datové vstupy A-GPS, čidlo okolního osvětlení, digitální kompas, G-senzor, gyroskop, multi-touch kapacitní dotykový displej, snímač
Displej 4.3 v (110 mm) kapacitní S-LCD dotykový displej Gorilla skla s QHD (540 × 960) rozlišením na 256.15 PPI
Fotoaparát na zadní straně s 8 miliony pixelů (3264 x 2448) s automatickým ostřením a dvojitým LED bleskem a 1080p HD video záznamu @ 30 snímků / s, kohoutek k zaměření s digitálním zoomem
Fotoaparát na přední straně VGA pevné zaostření barevná kamera (0,3 megapixelů)
Kompatibilní média formáty audio AAC, AMR, OGG, M4A, MIDI, MP3, WAV, WMA
Video 1920 × 1080 (1080p HD) @ 30 snímků / s - 3GP, .3 G2, MP4, WMV, AVI, XVID
Vyzváněcí tóny a oznámení všechny kompatibilní audio formáty
Vibrace
Připojení 3.5 mm TRRS konektor, Bluetooth 3.0 s A2DP, FM přijímač (87,5 - 108 MHz) s RDS, Micro USB 2.0 (5-pin) port s Mobile High-Definition Link (MHL) pro USB nebo HDMI připojení, Wi-Fi 802.11b/g/n
Zdroj: wikipedia
HTC Sensation 4G photo pic image
Zdroj obrázku: wikipedia
public class ApokusActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
private static class SampleView extends View {
// CONSTRUCTOR
public SampleView(Context context) {
super(context);
setFocusable(true);
}
@Override
protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
canvas.drawColor(Color.GREEN);
Bitmap b = Bitmap.createBitmap(200, 200, Bitmap.Config.ALPHA_8);
paint.setColor(Color.BLUE);
Shader mShader = new LinearGradient(0, 0, 100, 70, new int[] {
Color.RED, Color.GREEN, Color.BLUE },
null, Shader.TileMode.MIRROR); // CLAMP MIRROR REPEAT
Canvas c = new Canvas(b);
paint.setShader(mShader);
//c.drawCircle(60, 60, 30, paint);
c.drawRect(0, 0, 200, 200, paint);
canvas.drawBitmap(b, 10,10, paint);
}
}
}
public class MainClass extends Activity {
ActivityManager activityManager;
MemoryInfo memoryInfo;
final String TAG = "MemInfo";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
memoryInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
Log.i(TAG, " memoryInfo.availMem " + memoryInfo.availMem);
Log.i(TAG, " memoryInfo.lowMemory " + memoryInfo.lowMemory);
Log.i(TAG, " memoryInfo.threshold " + memoryInfo.threshold);
Toast.makeText(getApplicationContext(), String.valueOf( memoryInfo.availMem), Toast.LENGTH_LONG)
.show();
} // end onCreate
}
String[] source = {"Hello","world","by","Android"};
String[] destination = new String[source.length];
System.arraycopy(source, 0, destination, 0, source.length);
HorizontalScrollView ScrollView LinearLayout horizontal vertical Android xml basic example and image.
[caption id="attachment_889" align="alignleft" width="200" caption="horizontal scrollview horizontalscrollview android"][/caption]
Other sample
[caption id="attachment_889" align="alignleft" width="200" caption="horizontal scrollview horizontalscrollview android"][/caption]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="//schemas.android.com/apk/res/android">
// horizontal and vertical Scrollview
<ScrollView android:id="@+id/ScrollView01"
android:layout_height="135px" android:layout_width="wrap_content"
android:scrollbars="horizontal|vertical">
// HorizontalScrollview
<HorizontalScrollView android:id="@+id/HorizontalScrollView01"
android:layout_height="fill_parent" android:layout_width="wrap_content">
<LinearLayout android:id="@+id/LinearLayout02"
android:layout_width="wrap_content" android:orientation="vertical"
android:layout_height="fill_parent">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1">
<TextView android:text="red" android:gravity="center_horizontal"
android:background="#aa0000" android:layout_width="200px"
android:layout_height="fill_parent" android:layout_weight="1" />
<TextView android:text="green" android:gravity="center_horizontal"
android:background="#00aa00" android:layout_width="200px"
android:layout_height="fill_parent" android:layout_weight="1" />
<TextView android:text="blue" android:gravity="center_horizontal"
android:background="#0000aa" android:layout_width="200px"
android:layout_height="fill_parent" android:layout_weight="1" />
<TextView android:text="yellow" android:gravity="center_horizontal"
android:background="#aaaa00" android:layout_width="200px"
android:layout_height="fill_parent" android:layout_weight="1" />
</LinearLayout>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1">
<TextView android:text="row one" android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView android:text="row two" android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView android:text="row three" android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView android:text="row four" android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
</ScrollView>
</LinearLayout>
Other sample
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/layout"
android:orientation="vertical" >
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello world! First TextView" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
Editace: 2011-10-03 13:57:17
Počet článků v kategorii: 396
Url:timer-task-timertask-run-cancel-android-example