public class Items {
private int img_id;
private String name;
public int getImg_id() {
return img_id;
}
public void setImg_id(int img_id) {
this.img_id = img_id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getExplain() {
return explain;
}
public void setExplain(String explain) {
this.explain = explain;
}
private String explain;
}
二、
[if !supportLists]1. [endif]编写一个程序,可以显示实时时间,按返回时有弹出对话框提示是否退出程序,按确认后退出程序。
[if !supportLists]2. [endif]编写一个程序,按下按钮后间隔10秒自动弹出一个Toast显示当前时间,按返回时有弹出对话框提示是否退出程序,按确认后退出程序。
public class MainActivity extends Activity implements OnClickListener{
private AnalogClock clock;
private Button btn,btn2;
private DateFormat df;
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.button1:
new AlertDialog.Builder(MainActivity.this)
.setTitle("退出提醒").setMessage("是否退出程序!")
.setNegativeButton("否", null)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
finish(); } }).show(); break;
case R.id.button2:
Date curDate = new Date(System.currentTimeMillis());
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dfs = df.format(curDate);
new AlertDialog.Builder(MainActivity.this)
.setTitle("时间").setMessage(dfs)
.setPositiveButton("返回", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
new AlertDialog.Builder(MainActivity.this)
.setTitle("退出提醒").setMessage("是否退出程序!")
.setNegativeButton("否", null)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
finish();
} }).show(); } }).show(); break;
default:
break;}}
[if !supportLists]3. [endif]编写一个程序,实现一个登录界面,在登录界面中包含一个复选按钮“记住我”,选择时保存用户名和密码,否则不保存,打开登录界面时,如果有保存的用户名和密码,则将保存的用户名和密码显示到对应控件中。
public void onClick(View v) {
// TODO Auto-generated method stub
boolean chk = ck.isChecked();
if(chk){
namet.setText("用户名:"+String.valueOf(name.getText().toString()));
pwdt.setText("密码:"+String.valueOf(pwd.getText().toString()));
new AlertDialog.Builder(MainActivity.this)
.setMessage("登陆记住密码 ").setPositiveButton("确认 ", null).show();
}
else{
new AlertDialog.Builder(MainActivity.this)
.setMessage("登陆未记住密码").setPositiveButton("确认", null).show(); }
[if !supportLists]4. [endif]编写一个程序,实现一个日记功能,将写好的日记保存到文件Diary中,点击浏览的时候查看日记内容。
public void onClick(View v) {
// TODO Auto-generated method stub
String neirong = et.getText().toString();
String dizi = "riji.text";
switch (v.getId()) {
case R.id.button1:
FileOutputStream out = null;
try {
out = context.openFileOutput(dizi, Context.MODE_PRIVATE);
out.write(neirong.getBytes("UTF-8"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
try {
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
break;
case R.id.button2:
FileInputStream in = null;
ByteArrayOutputStream bout = null;
byte[]buf = new byte[1024];
bout = new ByteArrayOutputStream();
int length = 0;
try {
in = context.openFileInput(dizi); //获得输入流
while((length=in.read(buf))!=-1){
bout.write(buf,0,length);
}
byte[] content = bout.toByteArray();
tv.setText(new String(content,"UTF-8")); //设置文本框为读取的内容
} catch (Exception e) {
e.printStackTrace();
}
tv.invalidate(); //刷新屏幕
try{
in.close();
bout.close();
}
catch(Exception e){}
break;
[if !supportLists]5. [endif]编写一个程序,实现图片的浏览,向左滑动显示下一张图片,向右滑动显示上一张图片。
package com.example.img;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
public class MainActivity extends Activity implements OnTouchListener{
int caozuo = 0;
float x1 = 0;
float x2 = 0;
public ImageView image;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image = (ImageView)findViewById(R.id.imageView1);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN)
x1 = event.getX();
if(event.getAction() == MotionEvent.ACTION_UP){
x2 = event.getX();
if(x1-x2>=5){
caozuo =caozuo+1;
caozuo = caozuo%8;
if(caozuo==0)
{
caozuo ++;
}
image.setImageResource(R.drawable.a_1+caozuo);
}
if(x2-x1>=5){
caozuo =caozuo-1;
if(caozuo<=0){
caozuo = 7;
}
image.setImageResource(R.drawable.a_1+caozuo);
}
}
return false;
}
}//注意要添加照片进入文件中
[if !supportLists]6. [endif]编写一个程序,通过Handler和Thread或Runnable实现以10秒时间显示完进度条进度。
private ProgressBar progress;
private int max = 100,current = 0,step = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progress = (ProgressBar)findViewById(R.id.progressBar3);
progress.setMax(max);
progress.setProgress(0);
step = max/10;
new Thread(new Runnable() {
int i =1;
@Override
public void run() {
// TODO Auto-generated method stub
try {
while (max!=progress.getProgress()) {
Log.i("次数", i + "");
i++;
progress.setProgress(current + step);
current = progress.getProgress();
Thread.sleep(1000);
}
} catch (Exception e) {
// TODO: handle exception
}}
}).start();
}
[if !supportLists]7. [endif]编写一个程序,通过AsyncTask实现以20秒时间显示完进度条进度。
package com.example.jindutiao20s;
import android.os.AsyncTask;
import android.os.Bundle;
. import android.app.Activity;. import android.view.Menu;
import android.widget.ProgressBar;
import android.widget.TextView;.
. public class MainActivity extends Activity {.
private ProgressBar myBar;
private TextView textView;
@Override
. protected void onCreate(Bundle savedInstanceState) {
. super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
myBar = (ProgressBar)findViewById(R.id.progressBar1);
textView = (TextView)findViewById(R.id.textView1);
MyAsync my = new MyAsync();
my.execute();
}
class MyAsync extends AsyncTask{
int index = 0;
@Override
. protected void onPreExecute() {
. // TODO Auto-generated method stub
super.onPreExecute();
. textView.setText("0%");
}
protected Integer doInBackground(Void... params) {.
try {
for(int i =0;i<=20;i++){
Thread.sleep(1000);
index ++;
publishProgress(index);
}
. } catch (Exception e) {
// TODO: handle exception
}
return null;
}
. @Override
. protected void onProgressUpdate(Integer... values) {
// TODO Auto-generated method stub
. super.onProgressUpdate(values);
. textView.setText(values[0]*5+"%");
. myBar.setProgress(index*5);
. }
. @Override
. protected void onPostExecute(Integer result) {
. // TODO Auto-generated method stub
. super.onPostExecute(result);
. }
.
.
. }
.
.
. @Override. public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;. }
}
[if !supportLists]8. [endif]编写一个程序,手动绑定列表控件ListView,每条记录中包含图片,名称和描述。
两个布局布局1 listview布局二 对一个item进行布局 图片文字
三类主类调用该
package com.example.bangding;
import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ListView;
public class MainActivity extends Activity {
private List list;
private ListView listview;
private MyAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list = new ArrayList();
listview = (ListView)findViewById(R.id.listView1);
init();
}
private void init()
{
for (int i =1;i<=10;i++)
{
Items items = new Items();
items.setImg_id(R.drawable.a_1+i);
items.setName("名字:" + i);
items.setExplain("解释: "+ i);
list.add(items);
adapter = new MyAdapter(MainActivity.this,list);
listview.setAdapter(adapter);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Items类 声明
package com.example.bangding;
public class Items {
public int getImg_id() {
return img_id;
}
public void setImg_id(int img_id) {
this.img_id = img_id;
}
public String getExplain() {
return explain;
}
public void setExplain(String explain) {
this.explain = explain;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
private int img_id;
private String name;
private String explain;
}
Myadapter进行布局 线程
package com.example.bangding;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;
public class MyAdapter extends BaseAdapter {
private List list ;
private LayoutInflater inflater;
public MyAdapter(Context context,List list)
{
this.list = list;
inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view;
ViewHolder holder;
if(convertView==null)
{
view = inflater.inflate(R.layout.myactivity,null);
holder = new ViewHolder(view);
view.setTag(holder);
}
else
{
view = convertView;
holder = (ViewHolder) view.getTag();
}
Items items = list.get(position);
holder.img.setImageResource(items.getImg_id());
holder.name.setText(items.getName());
holder.explain.setText(items.getExplain());
return view;
}
class ViewHolder
{
private ImageView img;
private TextView name;
private TextView explain;
public ViewHolder(View view)
{
img = (ImageView)view.findViewById(R.id.imageView1);
name = (TextView)view.findViewById(R.id.textView1);
explain = (TextView)view.findViewById(R.id.textView2);
}
}
}
[if !supportLists]9. [endif]编写一个程序,通过使用Service来实现简单的播放器。
public class Myservice extends Service {
private MediaPlayer player;
private boolean ispaused = false;
private int position =0;
@Override
public void onCreate() {//最一开始会执性这个方法 如果服务在启动之中就不会启动这个方法直接调用onStartCommand 方法
super.onCreate();
Log.i("TAG","开始播放");
player = MediaPlayer.create(this,R.raw.qiyueshang);}
public void onDestroy() {//停止服务
super.onDestroy();
if(player != null)
player.stop(); }
public void Play(int pos)//播放
{
if(player!=null) {
player.start();
Log.i("TAG","开始播放");
player.seekTo(pos); } }
public void Pause()//暂停
{
if(player != null && player.isPlaying()) {
position = player.getCurrentPosition();//获取播放位置
player.pause();//暂停音乐
ispaused = true; }
else if(ispaused) {
Play(position); } }
public void Rest()//重放
{ if(player!=null)
Play(0); }
@Override
public int onStartCommand(Intent intent, int flags, int startId) {//开始服务
int flag = intent.getIntExtra("MSG",0);
if(flag==1)
{Play(0);}
else if(flag==2)
{Pause();}
else if(flag==3)
{Rest();}
Log.i("MSG",flag+"");
return super.onStartCommand(intent, flags, startId);
}
public IBinder onBind(Intent intent) {
return null;
}
}
[if !supportLists]10. [endif]编写一个程序,实现在状态栏提示有新短消息,展开状态栏点击消息时弹出详细信息界面。
public class NotifaicationActivity extends AppCompatActivity implements View.OnClickListener{
private Notification notification;
private Button send_notifiaction,stop_notification;
private NotificationManager manager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
send_notifiaction = (Button)findViewById(R.id.send_notification);
stop_notification = (Button)findViewById(R.id.stop_notification);
send_notifiaction.setOnClickListener(this);
stop_notification.setOnClickListener(this);
//第一步首先获取Notification管理对象
manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
//第二步获取Notification.Builder对象
Notification.Builder builder = new Notification.Builder(this);
//设置小图标
builder.setSmallIcon(R.mipmap.ic_launcher);
//提示音 振动 闪烁都是默认
builder.setDefaults(Notification.DEFAULT_ALL);
builder.setTicker("短信");
builder.setContentTitle("有短信");
builder.setContentText("短信来了");
Intent intent = new Intent(this,NotifaicationActivity.class);
//生成PendingIntene对象
PendingIntent pendingIntent = PendingIntent.getActivity(this,1,intent,0);
//设置跳转页面
builder.setContentIntent(pendingIntent);
//获得Notifaication对象
notification = builder.build();
}
@Override
public void onClick(View v) {
switch (v.getId())
{
case R.id.send_notification:
manager.notify(1,notification);//第一个时标识号 第二个是对象
break;
case R.id.stop_notification:
manager.cancel(1);
break;
}
}
}
[if !supportLists]11. [endif]编写一个程序,实现ListView显示好友列表信息,要求使用BaseAdapter。
public class MyAdapter extends BaseAdapter {
private List list ;
private LayoutInflater inflater;
public MyAdapter(Context context,List list)
{
this.list = list;
inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view;
ViewHolder holder;
if(convertView==null)
{
view = inflater.inflate(R.layout.item,null);
holder = new ViewHolder(view);
view.setTag(holder);
}
else
{
view = convertView;
holder = (ViewHolder) view.getTag();
}
Items items = list.get(position);
holder.img.setImageResource(items.getImg_id());
holder.name.setText(items.getName());
holder.explain.setText(items.getExplain());
return view;
}
class ViewHolder
{
private ImageView img;
private TextView name;
private TextView explain;
public ViewHolder(View view)
{
img = (ImageView)view.findViewById(R.id.imageView);
name = (TextView)view.findViewById(R.id.name);
explain = (TextView)view.findViewById(R.id.explain);
}
}
}
[if !supportLists]12. [endif]编写一个程序,实现点击一个按钮,打开一个新的Activity并传递“hello”,在新的Activity,接收传递过来的“hello”,将“hello”改成“hello world”,结束当前Activity并将需要修改后的值返回并关闭当前窗体。
public class IntentFirstActivity extends AppCompatActivity {
private Button send;
private EditText edit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intent_first);
send = (Button)findViewById(R.id.send_message);
edit = (EditText)findViewById(R.id.input);
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(IntentFirstActivity.this,IntentSecondActivity.class);
intent.putExtra("MSG",edit.getText().toString());
startActivityForResult(intent,2);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
edit.setText(data.getStringExtra("MSG"));
Toast.makeText(this,"收到新的值了",Toast.LENGTH_SHORT).show();
}
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intent_second);
send = (Button)findViewById(R.id.transition_msg);
Msg = (EditText)findViewById(R.id.return_msg);
receive_msg = (TextView)findViewById(R.id.receive);
receive_msg.setText("收到的信息为:" + getIntent().getStringExtra("MSG"));
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.putExtra("MSG",Msg.getText().toString());
//将修改的结果返回给上一个intent
setResult(1,intent);
finish();
}
});
}
}
三、
1.实现个人通讯录管理,主界面中包含添加按钮和ListView,能实现通讯录的添加和管理;所有通讯录信息通过ListView控件显示,长按ListView中的一项,出现以下功能选项:
呼叫、编辑联系人、删除联系人,分别实现这几个功能。
2.实现个人通讯录管理,主界面中包含添加按钮和ListView,能实现通讯录的添加和管理;所有通讯录信息通过ListView控件显示,长按ListView中的一项,出现以下功能选项:
复制、浏览联系人、删除联系人,分别实现这几个功能。
3.实现个人备忘录管理,主界面中包含添加按钮和ListView,能实现对备忘录的添加和管理;所有备忘录信息通过ListView控件显示,长按ListView中的一项,出现以下功能选项:
复制、编辑、删除,分别实现这几个功能。
4.实现个人备忘录管理,主界面中包含添加按钮和ListView,能实现对备忘录的添加和管理;所有备忘录信息通过ListView控件显示,长按ListView中的一项,出现以下功能选项:
复制、浏览、删除,分别实现这几个功能。
5.实现学生管理,登录界面,实现用户的登录,登录成功后,显示添加学生信息界面,学生信息包括学号、姓名、学院、专业和性别,输入完成后点击添加按钮添加到数据库中。要求:选择学院时专业发生相应的变化,性别采用单选按钮。
6.实现收货管理,包括以下功能:
1)用户登录功能;
2)货物管理功能,长按某条记录进行编辑和删除,或点击全部删除,清空所有收到的货物列表;
3)收货功能,货物信息:货物名称、件数、运费、目的地、收货人、电话等信息。
7.实现挂号预约系统,包括以下功能:
1)挂号预约,包括姓名、性别、年龄、地址、所挂科室等;
2)挂号预约管理,使用ListView实现,可删除或重新预约。
8.个人理财系统,包括以下功能:
1)支出录入:日期、金额、项目
2)收入录入:日期、金额、项目
3)支出收入列表,查询一个时间段的收入或支出情况并汇总。
9.日记系统,包括以下功能:
1)写日记,包括日期、天气、标题、内容等;
2)日记列表,根据条件查询日记,能实现对日记信息的显示,点击一条日记信息,显示日记详细内容,长按每条记录,能弹出对日记信息的修改、删除。
10.作业系统,包括以下功能:
1)记录作业,包括日期、作业类型(语文或数学等)、作业内容
2)显示作业列表,点击某项作业,转到作业详细信息界面,在该界面,可设置作业已完成、未做、不会等标识。
11.考勤系统,包括以下功能:
1)记录考勤,包括日期,年级,班级,总人数,旷课人数,请假人数;
2)记录旷课人具体信息,包括日期,年级,班级,旷课人姓名
3)显示考勤列表