안드로이드 - 다중 페이지 개발
1.1 응용 프로그램에 여러 개의 시작 입구를 설정하려면 다음과 같이 설정해야 한다.
<activity android:name=".Main2Activity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
intent-filter>
activity>
1.2 application节点下的icon和label可以和activity节点下不一样 如果activity自己配置了icon和label属性使用自己的.
2.意图
1.显示意图:通过设置具体的包名类名开启页面
2.隐式意图:通过设置一组动作或者数据开启页面
3.思考什么时候用显示 什么时候用隐式:开系统应用的页面用隐式 自己应用页面用显示
3.人品计算器
功能:计算人品
代码实现过程:
1.实现UI
2.mainActivity代码如下:
public class MainActivity extends AppCompatActivity {
private EditText et_name;
private RadioGroup rg_group;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//1.
et_name = (EditText) findViewById(R.id.et_name);
rg_group = (RadioGroup) findViewById(R.id.rg_group);
}
//
public void click(View view) {
//1.
String name = et_name.getText().toString().trim();
//2. name
if (TextUtils.isEmpty(name)){
Toast.makeText(this, "name ", Toast.LENGTH_SHORT).show();
return;
}
//3.
int sex = 0;
int checkedRadioButtonId = rg_group.getCheckedRadioButtonId();
switch (checkedRadioButtonId){
case R.id.rb_male: //
sex = 1;
break;
case R.id.rb_female: //
sex = 2;
break;
case R.id.rb_other: //
sex = 3;
break;
}
//4.
if (sex == 0){
Toast.makeText(this, " ", Toast.LENGTH_SHORT).show();
return;
}
//5.
Intent intent = new Intent(this, ResultActivity.class);
//6. map( : )
intent.putExtra("name",name);
intent.putExtra("sex",sex);
//7.
startActivity(intent);
- }
}
3. :
public class ResultActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
//1.
TextView tv_name = (TextView) findViewById(R.id.tv_name);
TextView tv_sex = (TextView) findViewById(R.id.tv_sex);
TextView tv_result = (TextView) findViewById(R.id.tv_result);
//2.
Intent intent = getIntent(); //
String name = intent.getStringExtra("name");
int sex = intent.getIntExtra("sex", 0);
//3.
tv_name.setText(name);
switch (sex){
case 1: //
tv_sex.setText(" ");
break;
case 2: //
tv_sex.setText(" ");
break;
case 3: //
tv_sex.setText(" ");
break;
}
//4.
Random random = new Random();
int score = random.nextInt(101);
if (score> 90){
tv_result.setText(" ");
}else if (score > 75){
tv_result.setText(" , ");
}else if (score > 60){
tv_result.setText(" ");
}else{
tv_result.setText(" 。 ?");
}
}
}
4.
public class MainActivity extends AppCompatActivity {
String[] objects = { " , ; , ; , 。 ..."
," , , , 。 , , 。 , , ..."
," , ; , 。 , , , ..."
," , : , ; , ; , ; ..."};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//1, listview
ListView lv = (ListView) findViewById(R.id.lv);
//2. listview
lv.setAdapter(new ArrayAdapter<String>(getApplicationContext(),R.layout.item,R.id.tv,objects));
//3. listview button:
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
// list
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
//4.
String data = objects[position];
//5.
Intent intent = new Intent();
//5.1
intent.setAction("android.intent.action.SEND");
intent.addCategory("android.intent.category.DEFAULT");
intent.setType("text/plain");
//5.2 data
intent.putExtra("sms_body",data);
//6.
startActivity(intent);
}
});
}
5.
2 .3 : 2 A B A B
2 ,A B , B , B A
1. UI
2.mainActivity
public class MainActivity extends AppCompatActivity {
private EditText et_context;
private EditText et_number;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//1.
et_context = (EditText) findViewById(R.id.et_content);
et_number = (EditText) findViewById(R.id.et_number);
}
// ContactActivity
public void add(View view) {
Intent intent = new Intent(this, ContactActivity.class);
// startActivity(intent);
//
startActivityForResult(intent,1);
}
//
public void click(View view) {
Intent intent = new Intent(this, SmsTemplateActivity.class);
startActivityForResult(intent,2);
}
//
public void send(View view) {
//1.
String content = et_context.getText().toString().trim();
String number = et_number.getText().toString().trim();
//2. smsmanager
SmsManager smsmanager = SmsManager.getDefault();
//3.
ArrayList<String> smss = smsmanager.divideMessage(content);
for (String sms : smss) {
//4.
smsmanager.sendTextMessage(number,null,sms,null,null);
}
}
// finish
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == 10){
//
//1.
String phone = data.getStringExtra("phone");
//2. phone EditText
et_number.setText(phone);
}else if (resultCode == 20){
//1.
String smsContent = data.getStringExtra("smsContent");
//2. smsContent EditText
et_context.setText(smsContent);
}
}
}
3. :
package com.itheima.smssend;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.format.Formatter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import org.w3c.dom.Text;
import java.util.ArrayList;
import java.util.List;
public class ContactActivity extends AppCompatActivity {
private List<Person> lists;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contact);
//1. listview
ListView lv_contact = (ListView) findViewById(R.id.lv_contact);
//2. ( )
lists = new ArrayList<>();
for (int i = 0; i <= 10; i++) {
Person person = new Person();
person.setName("zhangsan"+i);
person.setPhone("110"+i);
lists.add(person);
}
//3. listview
lv_contact.setAdapter(new MyAdapter());
//4. listview
lv_contact.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
//5.
String phone = lists.get(position).getPhone();
//5.1
Intent intent = new Intent();
intent.putExtra("phone",phone);
//5.2
setResult(10,intent);
//6.
finish(); // onActivityResult
}
});
}
// listview
class MyAdapter extends BaseAdapter{
@Override
public int getCount() {
return lists.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//0. listview
View view;
if (convertView == null){
view = View.inflate(getApplicationContext(),R.layout.item,null);
}else{
view = convertView;
}
//1.
TextView tv_name = (TextView) view.findViewById(R.id.tv_name);
TextView tv_phone = (TextView) view.findViewById(R.id.tv_phone);
//2.
tv_name.setText(lists.get(position).getName());
tv_phone.setText(lists.get(position).getPhone());
return view;
}
}
}
4.
public class SmsTemplateActivity extends AppCompatActivity {
String objects[] = { " , "," , "," , "," , "};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sms_template);
//1.
ListView listView = (ListView) findViewById(R.id.lv);
listView.setAdapter(new ArrayAdapter<String>(getApplicationContext(),R.layout.smstemplate_item,R.id.textView,objects));
//2. listview
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
//3.
String smsContent = objects[position];
//4.
Intent intent = new Intent();
intent.putExtra("smsContent",smsContent);
//5.
setResult(20,intent);
//6. finsih
finish();
}
});
}
}
6.Activity
1.onCreate activity
2.onDestory activity
3.onStart activity ( )
4.onStop activity
5.onResume ( )
6.onPause
7.onRestart
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.