我想獲得一個時間戳成一個文本視圖或任何視圖的活動,將提供時間,從一個按鈕打開活動的時間加上顯示輸入從兩個編輯文本到文本視圖的單獨活動。例如:從設備獲取時間戳以顯示在textview中?
活動Main
:
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
}
});
}
}
包含該XML佈局和視圖:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
現在我想從兩個編輯文本的用戶輸入而打開此下一個活動使用按鈕上的onClick加上顯示點擊按鈕時的時間戳:
import android.app.Activity;
import android.os.Bundle;
public class Main2 extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
}
}
哪個膨脹這個XML佈局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TextView" android:textSize="20dp"/>
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TextView" android:textSize="20dp"/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
所以,我要實現以下目標:
editText1 -----------> textView1
editText2 -----------> textView2
Phone's time stamp textview3
和開放與按鈕的點擊MAIN2活動。因此,editText1是一個EditText,它將接受用戶輸入並將該值返回到textView1中,對editText2和textView2也是如此,但最重要的是我想要點擊按鈕的時間以及返回到textView3的時間。
現在我知道如何將一個edittext的值返回到另一個activity中的textview,但不是兩個並獲取時間戳。
LAS_VEGAS OK,我得到了兩個標識符的工作,但得到對這裏的時間戳的錯誤是我儘可能代碼:
這是我的第一個活動的onClick方法:
EditText edit = (EditText) findViewById(R.id.etTitle);
EditText editP = (EditText) findViewById(R.id.etPrice);
long currentTime = System.currentTimeMillis();
Intent intent = new Intent(Post.this, PostSet.class);
intent.putExtra("com.main.espress.POSTSET", `edit.getText().toString());`
intent.putExtra("com.main.espress.NEW", editP.getText().toString());
intent.putExtra("currentTime", currentTime);
startActivity(intent);
這是我的第二個活動有:
TextView tv1 = (TextView) findViewById (R.id.tvTitleText);
TextView tv2 = (TextView) findViewById (R.id.tvPrice);
TextView tv3 = (TextView) findViewById (R.id.tvTimeStamp);
Intent intent = getIntent();
String edit = intent.getStringExtra("com.main.express.POSTSET");
String editP = intent.getStringExtra("com.main.espress.NEW");
long currentTime = extras.getLong("currentTime");
tv1.setText(edit);
tv2.setText(editP);
tv3.setText(currentTime);
檢查此示例:[Android - 獲取當前日期和時間](http://goo.gl/tHqrV) –