So I'm new to Android programming and I'm trying to make an app that takes input data and saves them to the phone then sends them out via email. I'm curently stuck. My app currently has inputs that don't save and a share button that can take a text string and put it as the text in a text message. That's about all I've figured out so far.
My question for right now is: How can I take the text from an input (editText1) and set it as plain text to the share feature?
I've tried a lot of different things I've seen online and while I can get them to become error free, when I actually open the app, it crashes/stops when I open the list item.
Here's my fragment code that works:
package com.example.nextslidemenuapp;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
public class ItemDetailActivity extends FragmentActivity {
protected String mString;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_item_detail);
// Show the Up button in the action bar.
getActionBar().setDisplayHomeAsUpEnabled(true);
// savedInstanceState is non-null when there is fragment state
// saved from previous configurations of this activity
// (e.g. when rotating the screen from portrait to landscape).
// In this case, the fragment will automatically be re-added
// to its container so we don't need to manually add it.
// For more information, see the Fragments API guide at:
//
// http://developer.android.com/guide/components/fragments.html
//
if (savedInstanceState == null) {
// Create the detail fragment and add it to the activity
// using a fragment transaction.
Bundle arguments = new Bundle();
arguments.putString(ItemDetailFragment.ARG_ITEM_ID, getIntent()
.getStringExtra(ItemDetailFragment.ARG_ITEM_ID));
ItemDetailFragment fragment = new ItemDetailFragment();
fragment.setArguments(arguments);
getSupportFragmentManager().beginTransaction()
.add(R.id.item_detail_container, fragment).commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
if (itemId == R.id.action_share) {
sharePost();
}
if (itemId == android.R.id.home) {
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. Use NavUtils to allow users
// to navigate up one level in the application structure. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
//
NavUtils.navigateUpTo(this,
new Intent(this, ItemListActivity.class));
return true;
}
return super.onOptionsItemSelected(item);
}
final EditText ed1 = (EditText) findViewById(R.id.editText1);
String myString = "text";
private void sharePost() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, myString);
startActivity(Intent.createChooser(shareIntent,
getString(R.string.share_chooser_title)));
}
}
And here is the specific code I'm focused on editing:
final EditText ed1 = (EditText) findViewById(R.id.editText1);
String myString = "text";
private void sharePost() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, myString);
startActivity(Intent.createChooser(shareIntent,
getString(R.string.share_chooser_title)));
}
I'm trying to replace "text" with the code that pulls editText1. Eventually I want to concatenate a number of the input boxes together with some semicolons.
Thanks for any help!