在论坛里转也有好长时间了,怎么没看到有android方面的问题呢!
呵呵......那我先开个头吧!
在这里提问一点android方面的问题,这个可是我的毕业设计啊,现在还是初试
因为特殊原因,不得不先研究android,虽然java底子有点差
不说那么多,先贴代码和图片,问题最后提问
启动界面代码:
/*
* 欢迎界面
* */
public class Launch extends Activity {
Handler handler ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
handler=new Handler();
handler.postDelayed(update, 2000);
}
Runnable update=new Runnable(){
@Override
public void run() {
Intent intent=new Intent(Launch.this,Selections.class);
startActivity(intent);
finish();
}
};
}
功能选项界面代码:
/*
*
* 选项界面,按下菜单键,会出现选项
* */
public class Selections extends Activity{
private Intent allIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.selecticon);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(PublicUtils.GROUP, PublicUtils.MENU01, 0, R.string.aerobic);
menu.add(PublicUtils.GROUP, PublicUtils.MENU02, 1, R.string.arch);
menu.add(PublicUtils.GROUP, PublicUtils.MENU03, 1, R.string.interm);
menu.add(PublicUtils.GROUP, PublicUtils.MENU04, 1, R.string.power);
menu.add(PublicUtils.GROUP, PublicUtils.MENU05, 1, R.string.strength);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()){
case PublicUtils.MENU01:
allIntent=new Intent(this,AerobicMethod.class);
startActivity(allIntent);
return true;
case PublicUtils.MENU02:
allIntent=new Intent(this,ArchMethod.class);
startActivity(allIntent);
return true;
case PublicUtils.MENU03:
allIntent=new Intent(this,IntermiterMethod.class);
startActivity(allIntent);
return true;
case PublicUtils.MENU04:
allIntent=new Intent(this,PowerMethod.class);
startActivity(allIntent);
return true;
case PublicUtils.MENU05:
allIntent=new Intent(this,StrengthMethod.class);
startActivity(allIntent);
return true;
}
return true;
}
}
选择“强度型运动”后启动的界面代码
public class StrengthMethod extends Activity implements OnClickListener{
private Button startStrength;
private Button pauseStrength;
private Button markStrength;
private Button resetStrength;
private Button deleteStrength;
private TextView timeStrength;
private ListView listStrength;
private int startTime;
private boolean flag=false;
private boolean flag1=false;
private List<Integer> marksStrength;
private Handler mHandler;
private Handler startH;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.strength);
/*readEnvironment();
Toast.makeText(StrengthMethod.this, "读取成功", Toast.LENGTH_SHORT).show();*/
init();
startH=new Handler();
}
Runnable startR=new Runnable(){
public void run(){
if(flag){
startTime=startTime+1;
timeStrength.setText(PublicUtils.getTime(startTime));
startH.postDelayed(startR, 1000);
}
}
};
@Override
protected void onDestroy() {
super.onDestroy();
//保存环境
saveEnvironment();
Toast.makeText(this, "保存成功", Toast.LENGTH_SHORT).show();
}
//初始化控件
private void init(){
startStrength=(Button) findViewById(R.id.startStrength);
pauseStrength=(Button) findViewById(R.id.pauseStrength);
markStrength=(Button) findViewById(R.id.markStrength);
resetStrength=(Button) findViewById(R.id.resetStrength);
deleteStrength=(Button) findViewById(R.id.deleteStrength);
timeStrength=(TextView) findViewById(R.id.timeStrength);
listStrength=(ListView) findViewById(R.id.ListStrength);
startStrength.setOnClickListener(this);
pauseStrength.setOnClickListener(this);
markStrength.setOnClickListener(this);
resetStrength.setOnClickListener(this);
deleteStrength.setOnClickListener(this);
}
protected void onStartClick(){
flag=true;
startH.post(startR);
marksStrength=new ArrayList<Integer>();
}
protected void onMarkClick(){
if(startTime==0){
return ;
}
marksStrength.add(0, startTime);
refreshListStrength();
}
protected void onResetClick(){
startTime=0;
flag=true;
startH.post(startR);
}
//刷新列表
private void refreshListStrength() {
List<Map<String, Object>> data=new ArrayList<Map<String,Object>>();
int num=marksStrength.size();
for(Integer mark:marksStrength){
Map<String, Object> map=new HashMap<String, Object>();
map.put("num", num);
map.put("content", PublicUtils.getTime(mark));
num--;
data.add(map);
}
String[] marks=new String[]{"num","content"};
int[] id=new int[]{R.id.num,R.id.content};
SimpleAdapter adapter=new
SimpleAdapter(this,
data,
R.layout.item,
marks,
id);
listStrength.setAdapter(adapter);
}
//读取保存的数据
protected void readEnvironment(){
marksStrength=new ArrayList<Integer>();
SharedPreferences sharedStrength=getSharedPreferences("contentStrength",MODE_PRIVATE);
Map<String, Integer> marksMap=(Map<String, Integer>)sharedStrength.getAll();
for(int i=0;i<marksMap.size();i++){
Integer map=marksMap.get(""+i);
marksStrength.add(map);
}
refreshListStrength();
}
//保存数据
protected void saveEnvironment(){
SharedPreferences sharedStrength=getSharedPreferences("contentStrength",MODE_PRIVATE);
Editor editor=sharedStrength.edit();
editor.clear();
for(Integer mark:marksStrength){
editor.putInt(""+marksStrength.indexOf(mark), mark.intValue());
}
editor.commit();
}
//各个按钮
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.startStrength:
onStartClick();
break;
case R.id.pauseStrength:
flag=false;
break;
//记录按钮,就是保存数据到listview中
case R.id.markStrength:
onMarkClick();
break;
case R.id.resetStrength:
onResetClick();
break;
case R.id.deleteStrength:
marksStrength=new ArrayList<Integer>();
refreshListStrength();
break;
}
}
}
好了,其它几个功能选项的代码就不贴了,都大同小异。还有那些布局文件啥的也不贴了,没技术含量的;
额............问题来了!!!如果有手机的话,装在手机上,运行后,看起来没啥问题。可是如果不停在“功能选项”和选择”强度型运动“这两个界面切换
的话,问题就来了,直接崩溃!!!!!强制退出系统。我也看了,应该和”强度型运动“界面的代码有关,可是我就是查不出哪些原因
贴出此贴,一是,希望能和坛里的高手交流交流,二是,呵呵呵,帮我把问题解决了,实在头痛呢
有兴趣的可以加我球球号:2297731717,我把代码给你,咱一起进步!!!
|
组图打开中,请稍候......
|