Hi i have 2 Activitys in my app and i would take the data from the first activity and insert them on the second one.
Pics: I have 2 datepickers to select date range and i save it on texView and texView2.
Code: Main Activity
selectDate = (Button) findViewById(R.id.button); date = (TextView) findViewById(R.id.textView);
selectDate2 = (Button) findViewById(R.id.button2);
date2 = (TextView) findViewById(R.id.textView2);
selectDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
calendar = Calendar.getInstance();
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH);
dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
datePickerDialog = new DatePickerDialog(MainActivity.this,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int year, int month, int day) {
date.setText("Entrada: "+day + "/" + (month + 1) + "/" + year);
}
}, year, month, dayOfMonth);
datePickerDialog.show();
}
});
selectDate2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
calendar2 = calendar2.getInstance();
year2 = calendar2.get(Calendar.YEAR);
month2 = calendar2.get(Calendar.MONTH);
dayOfMonth2 = calendar2.get(Calendar.DAY_OF_MONTH);
datePickerDialog2 = new DatePickerDialog(MainActivity.this,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int year, int month, int day) {
date2.setText("Salida: "+day + "/" + (month + 1) + "/" + year);
}
}, year2, month2, dayOfMonth2);
datePickerDialog2.show();
}
});
Activity2:
package com.example.mand.consumirapirest;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class json extends AppCompatActivity {
TextView tvJSON;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_json);
setTextView();
}
public void setTextView() {
tvJSON = (TextView) findViewById(R.id.tvJSON);
textView = (TextView) findViewById(R.id.textView);
String s = textView.getText().toString();
tvJSON.setText(s);
//String text = textView.getText().toString();
//return text;
}
/*public String getText()
{
}*/
}
Any idea thanks..!