最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實(shí)現(xiàn)學(xué)生管理系統(tǒng)

 更新時(shí)間:2016年03月17日 16:57:16   作者:吳英強(qiáng)  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)學(xué)生管理系統(tǒng)的相關(guān)代碼,供大家學(xué)習(xí)借鑒,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android實(shí)現(xiàn)學(xué)生管理系統(tǒng)的關(guān)鍵性代碼,供大家參考,具體內(nèi)容如下

局部效果圖:

 

實(shí)現(xiàn)代碼:

1、布局

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
 package="com.itheima27.sutdentmanager" 
 android:versionCode="1" 
 android:versionName="1.0" > 
 
 <uses-sdk 
  android:minSdkVersion="8" 
  android:targetSdkVersion="17" /> 
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
 
 <application 
  android:allowBackup="true" 
  android:icon="@drawable/ic_launcher" 
  android:label="@string/app_name" 
  android:theme="@style/AppTheme" > 
  <activity 
   android:name="com.itheima27.sutdentmanager.MainActivity" 
   android:label="@string/app_name" 
   android:theme="@android:style/Theme.NoTitleBar" > 
   <intent-filter> 
    <action android:name="android.intent.action.MAIN" /> 
 
    <category android:name="android.intent.category.LAUNCHER" /> 
   </intent-filter> 
  </activity> 
 </application> 
 
</manifest> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 android:background="@android:color/white" 
 android:orientation="vertical" > 
 
 <TextView 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" 
  android:layout_gravity="center_horizontal" 
  android:layout_marginTop="5dip" 
  android:text="學(xué)生管理系統(tǒng)" 
  android:textColor="#99CCFF" 
  android:textSize="23sp" /> 
 
 <RelativeLayout 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  android:layout_marginTop="5dip" 
  android:padding="5dip" > 
 
  <TextView 
   android:id="@+id/tv_name" 
   android:layout_width="wrap_content" 
   android:layout_height="wrap_content" 
   android:paddingLeft="15dip" 
   android:paddingRight="15dip" 
   android:text="姓名" 
   android:textSize="18sp" /> 
 
  <TextView 
   android:id="@+id/tv_sex" 
   android:layout_width="wrap_content" 
   android:layout_height="wrap_content" 
   android:layout_marginLeft="5dip" 
   android:layout_toRightOf="@id/tv_name" 
   android:paddingLeft="15dip" 
   android:paddingRight="15dip" 
   android:text="性別" 
   android:textSize="18sp" /> 
 
  <TextView 
   android:id="@+id/tv_age" 
   android:layout_width="wrap_content" 
   android:layout_height="wrap_content" 
   android:layout_marginLeft="5dip" 
   android:layout_toRightOf="@id/tv_sex" 
   android:paddingLeft="15dip" 
   android:paddingRight="15dip" 
   android:text="年齡" 
   android:textSize="18sp" /> 
 
  <EditText 
   android:id="@+id/et_name" 
   android:layout_width="wrap_content" 
   android:layout_height="wrap_content" 
   android:layout_alignLeft="@id/tv_name" 
   android:layout_alignRight="@id/tv_name" 
   android:layout_below="@id/tv_name" 
   android:singleLine="true" /> 
 
  <EditText 
   android:id="@+id/et_sex" 
   android:layout_width="wrap_content" 
   android:layout_height="wrap_content" 
   android:layout_alignLeft="@id/tv_sex" 
   android:layout_alignRight="@id/tv_sex" 
   android:layout_below="@id/tv_sex" 
   android:singleLine="true" /> 
 
  <EditText 
   android:id="@+id/et_age" 
   android:layout_width="wrap_content" 
   android:layout_height="wrap_content" 
   android:layout_alignLeft="@id/tv_age" 
   android:layout_alignRight="@id/tv_age" 
   android:layout_below="@id/tv_age" 
   android:inputType="number" 
   android:singleLine="true" /> 
 
  <Button 
   android:id="@+id/btn_add_student" 
   android:layout_width="wrap_content" 
   android:layout_height="wrap_content" 
   android:layout_alignBaseline="@id/et_age" 
   android:layout_toRightOf="@id/et_age" 
   android:text="添加學(xué)生" 
   android:textSize="20sp" /> 
 </RelativeLayout> 
 
 <ScrollView 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  android:layout_weight="1" > 
 
  <LinearLayout 
   android:id="@+id/ll_student_list" 
   android:layout_width="fill_parent" 
   android:layout_height="fill_parent" 
   android:layout_margin="1dip" 
   android:orientation="vertical" 
   android:padding="5dip" > 
  </LinearLayout> 
 </ScrollView> 
 
 <LinearLayout 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  android:layout_marginTop="5dip" 
  android:orientation="horizontal" > 
 
  <Button 
   android:id="@+id/btn_save" 
   android:layout_width="wrap_content" 
   android:layout_height="wrap_content" 
   android:layout_weight="1" 
   android:text="保存數(shù)據(jù)" 
   android:textSize="20sp" /> 
 
  <Button 
   android:id="@+id/btn_restore" 
   android:layout_width="wrap_content" 
   android:layout_height="wrap_content" 
   android:layout_weight="1" 
   android:text="恢復(fù)數(shù)據(jù)" 
   android:textSize="20sp" /> 
 </LinearLayout> 
 
</LinearLayout> 

2、關(guān)鍵代碼:

package com.itheima27.sutdentmanager.entities; 
 
public class Student { 
 
 private String name; 
 private String sex; 
 private Integer age; 
 public Student(String name, String sex, Integer age) { 
  super(); 
  this.name = name; 
  this.sex = sex; 
  this.age = age; 
 } 
 public Student() { 
  super(); 
  // TODO Auto-generated constructor stub 
 } 
 public String getName() { 
  return name; 
 } 
 public void setName(String name) { 
  this.name = name; 
 } 
 public String getSex() { 
  return sex; 
 } 
 public void setSex(String sex) { 
  this.sex = sex; 
 } 
 public Integer getAge() { 
  return age; 
 } 
 public void setAge(Integer age) { 
  this.age = age; 
 } 
 @Override 
 public String toString() { 
  return "Student [name=" + name + ", sex=" + sex + ", age=" + age + "]"; 
 } 
} 
package com.itheima27.sutdentmanager; 
 
import java.io.FileInputStream; 
import java.io.FileNotFoundException; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.util.ArrayList; 
import java.util.List; 
 
import org.xmlpull.v1.XmlPullParser; 
import org.xmlpull.v1.XmlPullParserException; 
import org.xmlpull.v1.XmlSerializer; 
 
import com.itheima27.sutdentmanager.entities.Student; 
 
import android.os.Bundle; 
import android.os.Environment; 
import android.app.Activity; 
import android.graphics.Color; 
import android.text.TextUtils; 
import android.util.Xml; 
import android.view.Menu; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.EditText; 
import android.widget.LinearLayout; 
import android.widget.TextView; 
import android.widget.Toast; 
 
public class MainActivity extends Activity implements OnClickListener { 
 
 private EditText etName; 
 private EditText etSex; 
 private EditText etAge; 
 private LinearLayout llStudentList; 
 private List<Student> studentList; 
 private String filePath; 
 
 @Override 
 protected void onCreate(Bundle savedInstanceState) { 
  super.onCreate(savedInstanceState); 
  setContentView(R.layout.activity_main); 
   
  init(); 
 } 
 
 private void init() { 
  etName = (EditText) findViewById(R.id.et_name); 
  etSex = (EditText) findViewById(R.id.et_sex); 
  etAge = (EditText) findViewById(R.id.et_age); 
   
  llStudentList = (LinearLayout) findViewById(R.id.ll_student_list); 
 
  findViewById(R.id.btn_save).setOnClickListener(this); 
  findViewById(R.id.btn_restore).setOnClickListener(this); 
  findViewById(R.id.btn_add_student).setOnClickListener(this); 
   
  studentList = new ArrayList<Student>(); 
  filePath = Environment.getExternalStorageDirectory().getPath() + "/student.xml"; 
 } 
 
 @Override 
 public void onClick(View v) { 
  switch (v.getId()) { 
  case R.id.btn_save: 
   if(studentList.size() > 0) { 
    if(saveStudent2Local()) { 
     Toast.makeText(this, "保存成功", 0).show(); 
    } else { 
     Toast.makeText(this, "保存失敗", 0).show(); 
    } 
   } else { 
    Toast.makeText(this, "當(dāng)前沒有數(shù)據(jù)", 0).show(); 
   } 
   break; 
  case R.id.btn_restore: 
   if(restoreStudentFromLocal()) { 
    Toast.makeText(this, "恢復(fù)成功", 0).show(); 
   } else { 
    Toast.makeText(this, "恢復(fù)失敗", 0).show(); 
   } 
   break; 
  case R.id.btn_add_student: 
   addStudent(); 
   break; 
  default: 
   break; 
  } 
 } 
  
 private boolean restoreStudentFromLocal() { 
  try { 
   XmlPullParser parser = Xml.newPullParser(); 
   parser.setInput(new FileInputStream(filePath), "utf-8"); 
    
   int eventType = parser.getEventType(); 
    
   studentList.clear(); 
    
   Student student = null; 
   String nodeName = null; 
   while(eventType != XmlPullParser.END_DOCUMENT) { 
    nodeName = parser.getName(); 
    switch (eventType) { 
    case XmlPullParser.START_TAG: 
     if("student".equals(nodeName)) { 
      student = new Student(); 
     } else if("name".equals(nodeName)) { 
      student.setName(parser.nextText()); 
     } else if("sex".equals(nodeName)) { 
      student.setSex(parser.nextText()); 
     } else if("age".equals(nodeName)) { 
      student.setAge(Integer.valueOf(parser.nextText())); 
     } 
     break; 
    case XmlPullParser.END_TAG: 
     if("student".equals(nodeName)) { 
      studentList.add(student); 
     } 
     break; 
    default: 
     break; 
    } 
    eventType = parser.next(); 
   } 
   refreshStudentList(); 
    
   return true; 
  } catch (Exception e) { 
   e.printStackTrace(); 
  } 
  return false; 
 } 
  
 private void refreshStudentList() { 
  llStudentList.removeAllViews(); 
  TextView childView; 
  for (Student student : studentList) { 
   childView = new TextView(this); 
   childView.setTextSize(23); 
   childView.setTextColor(Color.BLACK); 
   childView.setText("  " + student.getName() + "  " + student.getSex() + "  " + student.getAge()); 
   llStudentList.addView(childView); 
  } 
 } 
  
 private boolean saveStudent2Local() { 
  try { 
   XmlSerializer serializer = Xml.newSerializer(); 
   serializer.setOutput(new FileOutputStream(filePath), "utf-8"); 
    
   serializer.startDocument("utf-8", true); 
   serializer.startTag(null, "infos"); 
   for (Student stu : studentList) { 
    serializer.startTag(null, "student"); 
     
    serializer.startTag(null, "name"); 
    serializer.text(stu.getName()); 
    serializer.endTag(null, "name"); 
 
    serializer.startTag(null, "sex"); 
    serializer.text(stu.getSex()); 
    serializer.endTag(null, "sex"); 
 
    serializer.startTag(null, "age"); 
    serializer.text(String.valueOf(stu.getAge())); 
    serializer.endTag(null, "age"); 
     
    serializer.endTag(null, "student"); 
   } 
   serializer.endTag(null, "infos"); 
   serializer.endDocument(); 
   return true; 
  } catch (Exception e) { 
   e.printStackTrace(); 
  } 
  return false; 
 } 
 
 private void addStudent() { 
  String name = etName.getText().toString(); 
  String sex = etSex.getText().toString(); 
  String age = etAge.getText().toString(); 
   
  if(!TextUtils.isEmpty(name) 
    && !TextUtils.isEmpty(sex) 
    && !TextUtils.isEmpty(age)) { 
   studentList.add(new Student(name, sex, Integer.valueOf(age))); 
   TextView childView = new TextView(this); 
   childView.setTextSize(23); 
   childView.setTextColor(Color.BLACK); 
   childView.setText("  " + name + "  " + sex + "  " + age); 
   llStudentList.addView(childView); 
  } else { 
   Toast.makeText(this, "請正確輸入", 0).show(); 
  } 
 } 
} 

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助。

相關(guān)文章

  • Android 中無法取消標(biāo)題欄的問題小結(jié)(兩種方法)

    Android 中無法取消標(biāo)題欄的問題小結(jié)(兩種方法)

    我們都知道取消標(biāo)題欄有兩種方式,一種是在Java代碼中取消,另一種通過設(shè)置styles.xml文件中的Theme即可,下面就兩種方法給大家簡答介紹下
    2016-12-12
  • Android自定義相機(jī)、預(yù)覽區(qū)域裁剪

    Android自定義相機(jī)、預(yù)覽區(qū)域裁剪

    這篇文章主要為大家詳細(xì)介紹了Android自定義相機(jī)、預(yù)覽區(qū)域裁剪,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • Android中微信搶紅包助手的實(shí)現(xiàn)詳解

    Android中微信搶紅包助手的實(shí)現(xiàn)詳解

    本篇文章主要介紹了Android中微信搶紅包助手的實(shí)現(xiàn)詳解,通過利用AccessibilityService輔助服務(wù),監(jiān)測屏幕內(nèi)容,如監(jiān)聽狀態(tài)欄的信息,屏幕跳轉(zhuǎn)等,以此來實(shí)現(xiàn)自動拆紅包的功能,有興趣的可以了解一下。
    2017-02-02
  • 利用Android實(shí)現(xiàn)比較炫酷的自定義View

    利用Android實(shí)現(xiàn)比較炫酷的自定義View

    自定義View、多線程、網(wǎng)絡(luò),被認(rèn)為是Android開發(fā)者必須牢固掌握的最基礎(chǔ)的三大基本功,這篇文章主要給大家介紹了關(guān)于如何利用Android實(shí)現(xiàn)比較炫酷的自定義View的相關(guān)資料,需要的朋友可以參考下
    2021-07-07
  • 一款非常簡單酷炫的LoadingView動畫效果

    一款非常簡單酷炫的LoadingView動畫效果

    這篇文章主要為大家詳細(xì)介紹了一款非常簡單酷炫的LoadingView動畫效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-08-08
  • Flutter實(shí)現(xiàn)自定義下拉選擇框的示例詳解

    Flutter實(shí)現(xiàn)自定義下拉選擇框的示例詳解

    在一些列表頁面中,我們經(jīng)常會有上方篩選項(xiàng)的的需求,點(diǎn)擊出現(xiàn)一個下拉菜單,而在Flutter中,并沒有現(xiàn)成的這樣的組件,所以最好我們可以自己做一個。本文將利用Flutter實(shí)現(xiàn)自定義下拉選擇框,需要的可以參考一下
    2022-04-04
  • Android Activity之間的數(shù)據(jù)傳遞方法總結(jié)

    Android Activity之間的數(shù)據(jù)傳遞方法總結(jié)

    這篇文章主要給大家總結(jié)介紹了關(guān)于Android Activity之間的數(shù)據(jù)傳遞方法,文中通過示例代碼介紹的非常詳細(xì),對各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • Android XmlResourceParser出錯解決辦法

    Android XmlResourceParser出錯解決辦法

    這篇文章主要介紹了Android XmlResourceParser出錯解決辦法的相關(guān)資料,需要的朋友可以參考下
    2017-05-05
  • Android中實(shí)現(xiàn)圓角圖片的幾種方法

    Android中實(shí)現(xiàn)圓角圖片的幾種方法

    本篇文章主要介紹了Android中實(shí)現(xiàn)圓角圖片的幾種方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-06-06
  • Kotlin基礎(chǔ)學(xué)習(xí)之Deprecated與Suppress注解使用

    Kotlin基礎(chǔ)學(xué)習(xí)之Deprecated與Suppress注解使用

    這篇文章主要給大家介紹了關(guān)于Kotlin基礎(chǔ)學(xué)習(xí)之Deprecated與Suppress注解使用的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用Kotlin具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08

最新評論

留坝县| 永泰县| 彭水| 溧水县| 怀仁县| 金门县| 伊宁市| 和林格尔县| 齐齐哈尔市| 铁力市| 株洲市| 靖边县| 波密县| 关岭| 固原市| 金寨县| 钟祥市| 皮山县| 南和县| 长顺县| 辉县市| 固镇县| 平山县| 岳阳县| 太康县| 东至县| 石阡县| 都江堰市| 黄冈市| 盐池县| 姜堰市| 钟山县| 东辽县| 商水县| 定襄县| 襄樊市| 本溪市| 凤冈县| 太仓市| 宽城| 会宁县|