论坛上找别人的代码
除了activity的名字以外没有任何改动
原代码可行 每部分对应着放到自己建的一个project里就不行了 系统没有报错 不知道问题在哪里...
自己怀疑是intent的问题 可只是新手的猜测...
求赐教!!!
MainActivity.javapackage com.example.countdown;import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;public class MainActivity extends Activity { Button startButton;
EditText minuteText;
EditText secondText;
int minute;
int second;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main); startButton = (Button) findViewById(R.id.button_start);
minuteText = (EditText)findViewById(R.id.minute);
secondText = (EditText)findViewById(R.id.second);
startButton.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
if (!minuteText.getText().toString().equals("")) {
minute = Integer.parseInt(minuteText.getText().toString());
}
if (!secondText.getText().toString().equals("")) {
second = Integer.parseInt(secondText.getText().toString());
}
if (minute != 0 || second != 0) {
System.out.println(minute+":"+second);
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(minute);
list.add(second);
Intent intent = new Intent();
intent.setAction("com.example.countdown.StartActivity");
intent.putIntegerArrayListExtra("times", list);
startActivity(intent);
}
}
});
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
minute = 0;
second = 0;
super.onResume();
}
}StartActivity.javapackage com.example.countdown;import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Window;
import android.widget.TextView;public class StartActivity extends Activity{ static int minute = -1;
static int second = -1;
final static String tag = "tag";
TextView timeView;
Timer timer;
TimerTask timerTask;
Handler handler = new Handler(){
public void handleMessage(Message msg) {
System.out.println("handle!");
if (minute == 0) {
if (second == 0) {
timeView.setText("Time out !");
if (timer != null) {
timer.cancel();
timer = null;
}
if (timerTask != null) {
timerTask = null;
}
}else {
second--;
if (second >= 10) {
timeView.setText("0"+minute + ":" + second);
}else {
timeView.setText("0"+minute + ":0" + second);
}
}
}else {
if (second == 0) {
second =59;
minute--;
if (minute >= 10) {
timeView.setText(minute + ":" + second);
}else {
timeView.setText("0"+minute + ":" + second);
}
}else {
second--;
if (second >= 10) {
if (minute >= 10) {
timeView.setText(minute + ":" + second);
}else {
timeView.setText("0"+minute + ":" + second);
}
}else {
if (minute >= 10) {
timeView.setText(minute + ":0" + second);
}else {
timeView.setText("0"+minute + ":0" + second);
}
}
}
}
};
};
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.v(tag, "log---------->onCreate!");
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
timeView = (TextView)findViewById(R.id.myTime);
if (minute == -1 && second == -1) {
Intent intent = getIntent();
ArrayList<Integer> times = intent.getIntegerArrayListExtra("times");
minute = times.get(0);
second = times.get(1);
}
timeView.setText(minute + ":" + second);
timerTask = new TimerTask() {
@Override
public void run() {
Message msg = new Message();
msg.what = 0;
handler.sendMessage(msg);
}
};
timer = new Timer();
timer.schedule(timerTask,0,1000);
}
@Override
protected void onDestroy() {
Log.v(tag, "log---------->onDestroy!");
if (timer != null) {
timer.cancel();
timer = null;
}
if (timerTask != null) {
timerTask = null;
}
minute = -1;
second = -1;
super.onDestroy();
}
@Override
protected void onStart() {
Log.v(tag, "log---------->onStart!");
super.onStart();
}
@Override
protected void onStop() {
Log.v(tag, "log---------->onStop!");
super.onStop();
} @Override
protected void onResume() {
Log.v(tag, "log---------->onResume!");
super.onResume();
}
@Override
protected void onRestart() {
Log.v(tag, "log---------->onRestart!");
super.onRestart();
}
@Override
protected void onPause() {
Log.v(tag, "log---------->onPause!");
super.onPause();
}
}Javaintent
除了activity的名字以外没有任何改动
原代码可行 每部分对应着放到自己建的一个project里就不行了 系统没有报错 不知道问题在哪里...
自己怀疑是intent的问题 可只是新手的猜测...
求赐教!!!
MainActivity.javapackage com.example.countdown;import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;public class MainActivity extends Activity { Button startButton;
EditText minuteText;
EditText secondText;
int minute;
int second;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main); startButton = (Button) findViewById(R.id.button_start);
minuteText = (EditText)findViewById(R.id.minute);
secondText = (EditText)findViewById(R.id.second);
startButton.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
if (!minuteText.getText().toString().equals("")) {
minute = Integer.parseInt(minuteText.getText().toString());
}
if (!secondText.getText().toString().equals("")) {
second = Integer.parseInt(secondText.getText().toString());
}
if (minute != 0 || second != 0) {
System.out.println(minute+":"+second);
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(minute);
list.add(second);
Intent intent = new Intent();
intent.setAction("com.example.countdown.StartActivity");
intent.putIntegerArrayListExtra("times", list);
startActivity(intent);
}
}
});
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
minute = 0;
second = 0;
super.onResume();
}
}StartActivity.javapackage com.example.countdown;import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Window;
import android.widget.TextView;public class StartActivity extends Activity{ static int minute = -1;
static int second = -1;
final static String tag = "tag";
TextView timeView;
Timer timer;
TimerTask timerTask;
Handler handler = new Handler(){
public void handleMessage(Message msg) {
System.out.println("handle!");
if (minute == 0) {
if (second == 0) {
timeView.setText("Time out !");
if (timer != null) {
timer.cancel();
timer = null;
}
if (timerTask != null) {
timerTask = null;
}
}else {
second--;
if (second >= 10) {
timeView.setText("0"+minute + ":" + second);
}else {
timeView.setText("0"+minute + ":0" + second);
}
}
}else {
if (second == 0) {
second =59;
minute--;
if (minute >= 10) {
timeView.setText(minute + ":" + second);
}else {
timeView.setText("0"+minute + ":" + second);
}
}else {
second--;
if (second >= 10) {
if (minute >= 10) {
timeView.setText(minute + ":" + second);
}else {
timeView.setText("0"+minute + ":" + second);
}
}else {
if (minute >= 10) {
timeView.setText(minute + ":0" + second);
}else {
timeView.setText("0"+minute + ":0" + second);
}
}
}
}
};
};
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.v(tag, "log---------->onCreate!");
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
timeView = (TextView)findViewById(R.id.myTime);
if (minute == -1 && second == -1) {
Intent intent = getIntent();
ArrayList<Integer> times = intent.getIntegerArrayListExtra("times");
minute = times.get(0);
second = times.get(1);
}
timeView.setText(minute + ":" + second);
timerTask = new TimerTask() {
@Override
public void run() {
Message msg = new Message();
msg.what = 0;
handler.sendMessage(msg);
}
};
timer = new Timer();
timer.schedule(timerTask,0,1000);
}
@Override
protected void onDestroy() {
Log.v(tag, "log---------->onDestroy!");
if (timer != null) {
timer.cancel();
timer = null;
}
if (timerTask != null) {
timerTask = null;
}
minute = -1;
second = -1;
super.onDestroy();
}
@Override
protected void onStart() {
Log.v(tag, "log---------->onStart!");
super.onStart();
}
@Override
protected void onStop() {
Log.v(tag, "log---------->onStop!");
super.onStop();
} @Override
protected void onResume() {
Log.v(tag, "log---------->onResume!");
super.onResume();
}
@Override
protected void onRestart() {
Log.v(tag, "log---------->onRestart!");
super.onRestart();
}
@Override
protected void onPause() {
Log.v(tag, "log---------->onPause!");
super.onPause();
}
}Javaintent
解决方案 »
- 跪求指导!!!关于动态添加自定义控件的问题,给100分,在线等啊!!!!!!
- 把平板最下方的那行statusbar隐藏
- 有没有办法使用系统拨号但是不发广播
- 请教下读取网络数据的bytes = mmInStream.read(buffer),关闭socket为什么不扔出错误
- android Notification 置顶问题(android 状态栏中的通知置顶问题)
- 高分悬赏,一个小小的问题
- 如何获取控件的宽度
- 加载GridView问题
- Android画图-2
- 查询联系人要怎么分页用limit会被加到 where()里面
- android 系统的defaults.xml在哪
- eclipse里的界面跳转会停止运行是什么原因?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" > <DigitalClock
android:id="@+id/myClock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:textSize="30sp" /> <TextView
android:id="@+id/text_select"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/myClock"
android:layout_centerHorizontal="true"
android:text="@string/text_select"
android:textSize="20sp" />
<EditText android:id="@+id/minute"
android:layout_width="60dp"
android:layout_height="80dp"
android:layout_below="@id/text_select"
android:layout_alignLeft="@id/myClock"
android:layout_marginTop="20dp"
android:inputType="number"
android:gravity="center"
/>
<EditText android:id="@+id/second"
android:layout_width="60dp"
android:layout_height="80dp"
android:layout_below="@id/text_select"
android:layout_toRightOf="@id/minute"
android:layout_marginTop="20dp"
android:inputType="number"
android:gravity="center"
/> <Button
android:id="@+id/button_start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:padding="10dp"
android:text="@string/myButtonText"
android:textSize="30sp" /></RelativeLayout>
activity_start.xml<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView android:id="@+id/myTime"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="30dp"
android:textSize="100sp"
android:textColor="#9393FF"
android:gravity="center"
android:textStyle="bold" /></LinearLayout>
设置了时间之后按了下面的按钮就不行了
Intent intent = new Intent(); intent.setAction("com.example.countdown.StartActivity"); intent.putIntegerArrayListExtra("times", list); startActivity(intent);改成
Intent intent = new Intent(this,StartActivity.class);
startActivity();在AndroidManifest.xml文件中配置
Intent intent = new Intent(this,StartActivity.class);
startActivity(intent );在AndroidManifest.xml文件中配置
好像不让这么用
试过这样做 系统会提示错误 The constructor Intent(new View.OnClickListener(){}, Class<StartActivity>) is undefined