分类: LINUX
2008-11-18 11:01:44
xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView id="@+id/txt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello 中国"
/>
<Button id="@+id/go2"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="back">
<requestFocus />
Button>
LinearLayout>
public void setViewOneCommand()
...{
Button btn = (Button)findViewById(R.id.go);
btn.setOnClickListener(new View.OnClickListener()
...{
public void onClick(View v)
...{
helloTwo.this.setContentView(R.layout.second);
helloTwo.this.setViewTwoCommand();
}
});
Button btnExit=(Button)findViewById(R.id.exit);
btnExit.setOnClickListener(new View.OnClickListener()...{
public void onClick(View v)...{
helloTwo.this.finish();
}
});
}
public void setViewTwoCommand()
...{
Button btnBack=(Button)findViewById(R.id.go2);
btnBack.setOnClickListener(new View.OnClickListener()...{
public void onClick(View v)...{
helloTwo.this.setContentView(R.layout.main);
helloTwo.this.setViewOneCommand();
}
});
}
public void onCreate(Bundle icicle) ...{
super.onCreate(icicle);
setTheme(android.R.style.Theme_Dark);
setContentView(R.layout.main);
setViewOneCommand();
}
xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
package="cn.sharetop.android.hello.three">
<application android:icon="@drawable/icon">
<activity class=".HelloThree" android:label="@string/app_name">
<intent-filter>
<action android:value="android.intent.action.MAIN" />
<category android:value="android.intent.category.LAUNCHER" />
intent-filter>
activity>
<activity class=".HelloThreeB" android:label="@string/app_name">
activity>
application>
manifest> 
public void onCreate(Bundle icicle) ...{
super.onCreate(icicle);
setTheme(android.R.style.Theme_Dark);
setContentView(R.layout.main);
setViewOneCommand();
}
public void setViewOneCommand()
...{
Button btn = (Button)findViewById(R.id.go);
btn.setOnClickListener(new View.OnClickListener()
...{
public void onClick(View v)
...{
Intent intent = new Intent();
intent.setClass(HelloThree.this, HelloThreeB.class);
startActivity(intent);
finish();
}
});
Button btnExit=(Button)findViewById(R.id.exit);
btnExit.setOnClickListener(new View.OnClickListener()...{
public void onClick(View v)...{
HelloThree.this.finish();
}
});
}
public void setViewOneCommand()
...{
Button btn = (Button)findViewById(R.id.go);
btn.setOnClickListener(new View.OnClickListener()
...{
public void onClick(View v)
...{
try
...{
Intent intent = new Intent();
intent.setClass(HelloThree.this, HelloThreeB.class);
intent.setData(new ContentURI("One"));
startSubActivity(intent,REQUEST_TYPE_A);
}
catch(Exception ex)...{}
}
});
Button btnExit=(Button)findViewById(R.id.exit);
btnExit.setOnClickListener(new View.OnClickListener()...{
public void onClick(View v)...{
HelloThree.this.finish();
}
});
}
protected void onActivityResult(int requestCode, int resultCode,
String data, Bundle extras)
...{
if (requestCode == REQUEST_TYPE_A) ...{
if (resultCode == RESULT_OK) ...{
Log.v(TAG,data);
TextView txt = (TextView)findViewById(R.id.txt);
txt.setText(data);
}
}
}
private Intent i;
protected void onCreate(Bundle icicle) ...{
super.onCreate(icicle);
setContentView(R.layout.second);
i = getIntent();
android.util.Log.v(TAG,"onCreate");
Button btn = (Button)findViewById(R.id.go);
btn.setOnClickListener(new View.OnClickListener()...{
public void onClick(View v)...{
String result=HelloThreeB.this.i.getData().toString()+" And Two";
HelloThreeB.this.setResult(RESULT_OK,result);
finish();
}
});
TextView v = (TextView)findViewById(R.id.txt);
v.setText("Param is "+i.getData().toString());
}