<ViewSwitcher xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/viewSwitcher1" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/tableLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="50dp" > <ProgressBar android:id="@+id/progressBar1" style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </TableLayout> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/tableLayout2" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="50dp" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:text="Welcome to My App" android:textAppearance="?android:attr/textAppearanceMedium" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/pic_a" android:layout_marginTop="10dp" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:text="CopyRight 2012 www.ThaiCreate.Com" android:textAppearance="?android:attr/textAppearanceSmall" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Reload again" /> </TableLayout> </ViewSwitcher>
package com.myapp; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.annotation.SuppressLint; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.ViewSwitcher; public class MainActivity extends Activity { ViewSwitcher Vs; private static final int REFRESH_SCREEN = 1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // viewSwitcher1 Vs = (ViewSwitcher) findViewById(R.id.viewSwitcher1); startScan(); // Reload again Button btn1 = (Button) findViewById(R.id.button1); btn1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Vs.showPrevious(); startScan(); } }); } public void startScan() { new Thread() { public void run() { try{ Thread.sleep(5000); hRefresh.sendEmptyMessage(REFRESH_SCREEN); }catch(Exception e){ } } }.start(); } Handler hRefresh = new Handler(){ public void handleMessage(Message msg) { switch(msg.what){ case REFRESH_SCREEN: Vs.showNext(); break; default: break; } } }; @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/tableLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="50dp" > <ProgressBar android:id="@+id/progressBar1" style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </TableLayout>
package com.myapp; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.app.Activity; import android.content.Intent; public class MainActivity extends Activity { private static final int REFRESH_SCREEN = 1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); startScan(); } public void startScan() { new Thread() { public void run() { try{ Thread.sleep(5000); hRefresh.sendEmptyMessage(REFRESH_SCREEN); }catch(Exception e){ } } }.start(); } Handler hRefresh = new Handler(){ public void handleMessage(Message msg) { switch(msg.what){ case REFRESH_SCREEN: // Open ActivityForm2 Intent newActivity = new Intent(MainActivity.this,ActivityForm2.class); startActivity(newActivity); break; default: break; } } }; }
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/tableLayout2" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="50dp" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:text="Welcome to My App" android:textAppearance="?android:attr/textAppearanceMedium" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/pic_a" android:layout_marginTop="10dp" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:text="CopyRight 2012 www.ThaiCreate.Com" android:textAppearance="?android:attr/textAppearanceSmall" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Reload again" /> </TableLayout>
package com.myapp; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; public class ActivityForm2 extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_form2); // Reload again Button btn1 = (Button) findViewById(R.id.button1); btn1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Open MainActivity Intent newActivity = new Intent(ActivityForm2.this,MainActivity.class); startActivity(newActivity); } }); } }
<activity android:name="ActivityForm2" android:theme="@style/AppTheme" android:screenOrientation="portrait" android:label="@string/title_activity_main" />
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท