
一.将信息写入.INI文件中
1.所用的WINAPI函数原型为:
BOOL WritePrivateProfileString(
LPCTSTR lpAppName,
LPCTSTR lpKeyName,
LPCTSTR lpString,
LPCTSTR lpFileName
)
其中各参数的意义:
LPCTSTR lpAppName 是INI文件中的一个字段名.
LPCTSTR lpKeyName 是lpAppName下的一个键名,通俗讲就是变量名.
PCTSTR lpString 是键值,也就是变量的值,不过必须为LPCTSTR型或CString型的.
LPCTSTR lpFileName 是完整的INI文件名.
2.具体使用方法:设现有一名学生,需把他的姓名和年龄写入 c:/stud/student.ini 文件中.
CString strName,strTemp
int nAge
strName="张三"
nAge=12
::WritePrivateProfileString("StudentInfo","Name",strName,"c://stud//student.ini")
此时c:/stud/student.ini文件中的内容如下:
[StudentInfo]
Name=张三
.要将学生的年龄保存下来,只需将整型的值变为字符型即可:
strTemp.Format("%d",nAge)
::WritePrivateProfileString("StudentInfo","Age",strTemp,"c://stud//student.ini")
二.将信息从INI文件中读入程序中的变量.
1.所用的WINAPI函数原型为:
DWORD GetPrivateProfileString(
LPCTSTR lpAppName,
LPCTSTR lpKeyName,
LPCTSTR lpDefault,
LPTSTR lpReturnedString,
DWORD nSize,
LPCTSTR lpFileName
)
其中各参数的意义:
前二个参数与 WritePrivateProfileString中的意义一样.
lpDefault : 如果INI文件中没有前两个参数指定的字段名或键名,则将此值赋给变量.
lpReturnedString : 接收INI文件中的值的CString对象,即目的缓存器.
nSize : 目的缓存器的大小.
lpFileName : 是完整的INI文件名.
2.具体使用方法:现要将上一步中写入的学生的信息读入程序中.
CString strStudName
int nStudAge
GetPrivateProfileString("StudentInfo","Name","默认姓名",strStudName.GetBuffer(MAX_PATH),MAX_PATH,"c://stud//student.ini")
执行后 strStudName 的值为:"张三",若前两个参数有误,其值为:"默认姓名".
3.读入整型值要用另一个WINAPI函数:
UINT GetPrivateProfileInt(
LPCTSTR lpAppName,
LPCTSTR lpKeyName,
INT nDefault,
LPCTSTR lpFileName
)
这里的参数意义与上相同.使用方法如下:
nStudAge=GetPrivateProfileInt("StudentInfo","Age",10,"c://stud//student.ini")
利用ListView和数据库做一个学员信息管理系统。下面把做的代码复制下来,供大家参考。首页的布局main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout android:id="@+id/RelativeLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:id="@+id/bn_search_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="搜索"
android:gravity="center_vertical" />
<Button android:gravity="center"
android:text="@string/myButton"
android:id="@+id/btn_add_student"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/bn_search_id"
android:layout_toLeftOf="@+id/bn_select" />
<Button android:gravity="center_vertical"
android:text="选择"
android:id="@+id/bn_select"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"></Button>
</RelativeLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text=" ID姓 名 年 龄 性 别"
/>
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"/>
<LinearLayout
android:orientation="horizontal"
android:id="@+id/showLiner"
android:visibility="gone"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/bn_delete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="删除"
android:enabled="false"
/>
<Button
android:id="@+id/bn_selectall"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="全选"
/>
<Button
android:id="@+id/bn_canel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="取消"
/>
</LinearLayout>
</LinearLayout>
android学生信息管理系统源码 - mypanlong的专栏
http://blog.csdn.net/mypanlong/article/details/43851625
其余部分
public class Student {private String no
private String name
private Integer age
public String getNo() {
return no
}
public void setNo(String no) {
this.no = no
}
public String getName() {
return name
}
public void setName(String name) {
this.name = name
}
public Integer getAge() {
return age
}
public void setAge(Integer age) {
this.age = age
}
public void sign(String no, String name, int age) {
setNo(no)
setName(name)
setAge(age)
}
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)