I am trying to get a time stamp into a textview or any view for the matter in an activity that will give the time when the activity is opened from a button plus display the input from two edit text’s into text view’s that are in seperate activities. For example:
Activity 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) {
}
});
}
}
Which includes this xml layout and views:
<?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>
Now I want to get the user input from these two edit text’s while opening this next activity with the onClick from the button plus display the time stamp from the time the button was clicked:
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);
}
}
Which inflates this xml layout:
<?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>
So I want to accomplish the following:
editText1 -----------> textView1
editText2 -----------> textView2
Phone's time stamp textview3
and open Main2 activity with the click of the button. So editText1 is an EditText that will take user input and return that value into textView1, the same for editText2 and textView2, but on top of that I want to get the time the button is clicked and the time returned into textView3.
Now I know how to return the value of one edittext to a textview in another activity but not two and get a time stamp.
LAS_VEGAS
OK I got the two identifiers to work but getting an error on the time stamp here is what I have as far as code :
This is what I have in the first Activities onClick method:
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);
This is what my second Activity has:
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);
You can pass multiple values of data between activities using
Intent:Inside
onClick()In Activitiy
Main2: