https://docs.google.com/open?id=0B6sL60kI5J0mMDNPX2FkdDFRRE0
package cse.ust.buttonfun;
import android.app.Activity;
import android.view.View.OnClickListener;
import android.os.Bundle;
public class ButtonFunActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
------------------------------------------------------------------------------------------
package cse.ust.buttonfun;
import
import
import
import
import
import
android.app.Activity;
android.os.Bundle;
android.view.View;
android.view.View.OnClickListener;
android.widget.Button;
android.widget.TextView;
public class ButtonFunActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
Button leftBtn, rightBtn;
TextView displayText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Initialize the instances with UI elements
leftBtn = (Button) findViewById(R.id.leftBtn);
rightBtn = (Button) findViewById(R.id.rightBtn);
displayText = (TextView) findViewById(R.id.displayText);
// Set the OnClickListener
leftBtn.setOnClickListener(this);
rightBtn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
------------------------------------------------------------------------------------------------------------
package cse.ust.buttonfun;
import
import
import
import
import
import
android.app.Activity;
android.os.Bundle;
android.view.View;
android.view.View.OnClickListener;
android.widget.Button;
android.widget.TextView;
public class ButtonFunActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
Button leftBtn, rightBtn;
TextView displayText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Initialize the instances with UI elements
leftBtn = (Button) findViewById(R.id.leftBtn);
rightBtn = (Button) findViewById(R.id.rightBtn);
displayText = (TextView) findViewById(R.id.displayText);
// Set the OnClickListener
leftBtn.setOnClickListener(this);
rightBtn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v==leftBtn){
displayText.setText(R.string.left);
}else{
displayText.setText(R.string.right);
}
}
}
沒有留言:
張貼留言