一:第一步先创建一个项目,名字可以随便取但是首字母要大写
二:在项目里面我划线的地方进行编写代码
1:也可以在layout里面进行创建新的项目
点进去后点next
写完之后点击Finish就创建完成了
三:创建页面
1:先创建一个带有图片的页面
2:在创建一个可以登录或者注册的页面(这里我写的是注册系统)
3:在创建一个可以显示吐丝的页面
四:进行连接
1:找到第一个页面相对应得java代码段并书写代码和第二个(注册页面)进行连接
package com.example.day5;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
public class BarActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bar);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Intent it = new Intent(getApplicationContext(), MainActivity.class);
startActivity(it);
}
});
t.start();
}
}
2:第一个和第二个页面进行连接(找到第二个java代码段和上面一样)
package com.example.day5;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Spinner;
public class MainActivity extends Activity implements OnClickListener {
//1:定义id控件
private EditText etusername,etpwd;
private RadioButton rbM,rbW;
private CheckBox cb1,cb2,cb3,cb4;
private Button btnCommit,btnCancle;
private Spinner spItem;
String[] items = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//影藏状态栏
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
//影藏标题栏
getActionBar().hide();
setContentView(R.layout.activity_main);
// 2:找到id控件
init();
// 3:设置点击事件
btnCommit.setOnClickListener(this);
//准备数据
//标题数据
items = new String[]{"移动212","移动213","移动214","移动215"};
//使用适配器来进行页面和数据的链接
ArrayAdapter adapter = new ArrayAdapter(getApplicationContext(),
R.layout.ilte,items);
spItem.setAdapter(adapter);
}
private void init() {
etusername = (EditText) findViewById(R.id.et_username);
etpwd = (EditText) findViewById(R.id.et_pwd);
rbM = (RadioButton) findViewById(R.id.rd_M);
rbW = (RadioButton) findViewById(R.id.rd_W);
cb1 = (CheckBox) findViewById(R.id.cb_1);
cb2 = (CheckBox) findViewById(R.id.cb_2);
cb3 = (CheckBox) findViewById(R.id.cb_3);
cb4 = (CheckBox) findViewById(R.id.cb_4);
btnCommit = (Button) findViewById(R.id.btn_Commit);
btnCancle = (Button) findViewById(R.id.btn_Cancle);
spItem = (Spinner) findViewById(R.id.sp_Item);
}
@Override
public void onClick(View arg0) {
//4:获取用户名
String userName = etusername.getText().toString();
//5:获取密码
String pwd = etpwd.getText().toString();
//6:获取性别单选
String sex = "";
if(rbM.isChecked()){
sex = rbM.getText().toString();
}
if(rbW.isChecked()){
sex = rbW.getText().toString();
}
//7:获取爱好
String fav = "";
if(cb1.isChecked()){
fav += cb1.getText().toString();
}
if(cb2.isChecked()){
fav += cb2.getText().toString();
}
if(cb3.isChecked()){
fav += cb3.getText().toString();
}
if(cb4.isChecked()){
fav += cb4.getText().toString();
}
//7.2获取下拉列表选中的内容
int i = spItem.getSelectedItemPosition();
String spItem = items[i];
//8:传值跳转
Intent it = new Intent(getApplicationContext(),InfoActivity.class);
it.putExtra("userName",userName);
it.putExtra("pwd",pwd);
it.putExtra("sex",sex);
it.putExtra("fav",fav);
it.putExtra("spItem",spItem);
startActivity(it);
}
}
2.2:这里有个下拉列表的字体和背景修改
3:第二个页面和第三个页面进行连接
package com.example.day5;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.widget.TextView;
import android.widget.Toast;
public class InfoActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_info);
Intent it = getIntent();
String userName = it.getStringExtra("userName");
String pwd = it.getStringExtra("pwd");
String sex = it.getStringExtra("sex");
String fav = it.getStringExtra("fav");
String spItem = it.getStringExtra("spItem");
String str = userName + ":" + pwd + ":"+sex+":"+fav+":"+spItem;
Toast.makeText(getApplicationContext(), str, 1).show();
TextView tvShow = (TextView) findViewById(R.id.tv_show);
tvShow.setText(str);
}
}
五:运行
六:这样就可以看到实现3个页面的跳转l
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)