我打算6共享文本信息,但它始终只显示最后一个信息,即
share.putExtra(Intent.EXTRA_TEXT, Contact);
我还试图用一个字符串数组来存储所有的6个信息,即:
share.putExtra(Intent.EXTRA_TEXT, stringArray);
但是,它仍然无法正常工作。 任何人都可以帮忙吗? 谢谢。
我的代码:
public class SingleJobActivity extends Activity {
// JSON node keys
private static final String TAG_POSTNAME = "PostName";
private static final String TAG_LOCATION = "Location";
private static final String TAG_SALARY = "Salary";
private static final String TAG_RESPONSIBILITY = "Responsibility";
private static final String TAG_COMPANY = "Company";
private static final String TAG_CONTACT = "Contact";
String PostName;
String Location;
String Salary;
String Responsibility;
String Company;
String Contact;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single_job_json_parsing);
// getting intent data
Intent in = getIntent();
// Get JSON values from previous intent
PostName = in.getStringExtra(TAG_POSTNAME);
Location = in.getStringExtra(TAG_LOCATION);
Salary = in.getStringExtra(TAG_SALARY);
Responsibility = in.getStringExtra(TAG_RESPONSIBILITY);
Company = in.getStringExtra(TAG_COMPANY);
Contact = in.getStringExtra(TAG_CONTACT);
// Displaying all values on the screen
TextView lblPostName = (TextView) findViewById(R.id.PostName_label);
TextView lblLocation = (TextView) findViewById(R.id.Location_label);
TextView lblSalary = (TextView) findViewById(R.id.Salary_label);
TextView lblResponsibility = (TextView) findViewById(R.id.Responsibility_label);
TextView lblCompany = (TextView) findViewById(R.id.Company_label);
TextView lblContact = (TextView) findViewById(R.id.Contact_label);
lblPostName.setText(PostName);
lblLocation.setText(Location);
lblSalary.setText(Salary);
lblResponsibility.setText(Responsibility);
lblCompany.setText(Company);
lblContact.setText(Contact);
// listeners of our button
View.OnClickListener handler = new View.OnClickListener() {
public void onClick(View v) {
switch (v.getId()) {
case R.id.share:
shareTextUrl();
break;
}
}
};
// our button
findViewById(R.id.share).setOnClickListener(handler);
}
// Method to share either text or URL.
private void shareTextUrl() {
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("text/plain");
share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
// Add data to the intent, the receiving app will decide
// what to do with it.
share.putExtra(Intent.EXTRA_SUBJECT, "Job Information:");
share.putExtra(Intent.EXTRA_TEXT, PostName);
share.putExtra(Intent.EXTRA_TEXT, Location);
share.putExtra(Intent.EXTRA_TEXT, Salary);
share.putExtra(Intent.EXTRA_TEXT, Responsibility);
share.putExtra(Intent.EXTRA_TEXT, Company);
share.putExtra(Intent.EXTRA_TEXT, Contact);
startActivity(Intent.createChooser(share, "Share via"));
}
}