Part0301.java
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class Part0301 extends Activity {
/** Called when the activity is first created. */
//設定選單要顯示的內容,做為 ArrayAdapter 的資料來源
String[] CreditCardData = {"Google","Yahoo!","Apple"};
String[] CreditCardWeb = {"http://www.google.com","http://www.yahoo.com.tw","http://www.apple.com"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.layout0301);
/* 建立「陣列接收器」
android.R.layout.simple_list_item_1 一行text
android.R.layout.simple_list_item_2 一行title、一行text */
ArrayAdapter<String> arrayData = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, CreditCardData);
ListView CreditCardListView = (ListView)findViewById(R.id.ListView01);
CreditCardListView.setAdapter(arrayData); // 設定 ListView 的接收器, 做為選項的來源
CreditCardListView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setClass(Part0301.this, Part0302.class);
String Web = CreditCardWeb[arg2];
Bundle bundle = new Bundle();
bundle.putString("Web", Web);
intent.putExtras(bundle);
startActivity(intent);
}
});
}
}
layout0301.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我的最愛"
android:textSize="25sp"
android:layout_margin="10sp"
/>
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/ListView01"
/>
</LinearLayout>
Part0302.java
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;
import android.widget.TextView;
public class Part0302 extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.layout0302);
Bundle bundle0302 =this.getIntent().getExtras();
String Web = bundle0302.getString("Web");
WebView CreditCardWeb = (WebView)findViewById(R.id.WebView01);
CreditCardWeb.getSettings().setJavaScriptEnabled(true);
CreditCardWeb.loadUrl(Web);
}
}
layout0302.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/WebView01"
/></LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sam.test"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"/>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Part0301"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Part0302" />
</application>
</manifest>
留言列表