Take input from edittext, click to save and create new textview - Android Studio

Hello,
this time iI'm working on an app where you can write something and click to the save button.
The important thing is that if you click on the save button than you have a new created textview in the other activity
the class where you write a notice and click on save button
Code:
public class NewNoticeActivity extends AppCompatActivity {
Button saveButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_notice);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
public void onCancelClick(View view){
Intent intentNew = new Intent(view.getContext(), NewActivity.class);
startActivity(intentNew);
}
public void onSaveClick(View view){
saveButton = (Button) findViewById(R.id.saveButton);
saveButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
EditText editText = (EditText) findViewById(R.id.editText);
String notice= editText.getText().toString();
Intent intentSaveNotice = new Intent(view.getContext(), YourNoticesActivity.class);
intentSaveNotice .putExtra("my notice", notice);
startActivity(intentSaveNotice );
}
});
}
}
so what i tried to do is that you first have nothing in the YourNoticesActivity
and after clicking on save you have 1 more notice and so on
i hope you could understand me

Related

Having Trouble with SharedPreferences

So.. I stayed up all night and finally got XSharedPreferences to work with my module. But today when I tried to add other elements such as a Navigation Drawer, and have the preference page only show when tapped, it stopped working.
This is the MainActivity code that has been working just fine.
Working:
Code:
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null)
getFragmentManager().beginTransaction().replace(android.R.id.content, new PrefsFragment()).commit();
}
public static class PrefsFragment extends PreferenceFragment {
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getPreferenceManager().setSharedPreferencesMode(MODE_WORLD_READABLE);
addPreferencesFromResource(R.xml.prefs);
}
}
}
Below is the code where it stopped working. I tried back tracking and only with the code above does it work.
Not working:
Code:
public class MainActivity extends AppCompatActivity implements NavigationDrawerCallbacks {
/**
* Fragment managing the behaviors, interactions and presentation of the navigation drawer.
*/
private NavigationDrawerFragment mNavigationDrawerFragment;
private Toolbar mToolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
setSupportActionBar(mToolbar);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getFragmentManager().findFragmentById(R.id.fragment_drawer);
// Set up the drawer.
mNavigationDrawerFragment.setup(R.id.fragment_drawer, (DrawerLayout) findViewById(R.id.drawer), mToolbar);
// populate the navigation drawer
mNavigationDrawerFragment.setUserData("John Doe", "[email protected]", BitmapFactory.decodeResource(getResources(), R.drawable.avatar));
}
@Override
public void onNavigationDrawerItemSelected(int position) {
Fragment fragment;
switch (position) {
case 0: //search//todo
break;
case 1: //Minor theme fixes
fragment = getFragmentManager().findFragmentByTag(PrefsFragment.TAG);
if (fragment == null) {
fragment = new PrefsFragment();
}
android.app.FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, fragment, PrefsFragment.TAG)
.addToBackStack(null)
.commit();
break;
case 2: //Full themed apps
fragment = getFragmentManager().findFragmentByTag(PrefsFragment2.TAG_2);
if (fragment == null) {
fragment = new PrefsFragment2();
}
android.app.FragmentManager fragmentManager1 = getFragmentManager();
fragmentManager1.beginTransaction()
.replace(R.id.container, fragment, PrefsFragment2.TAG_2)
.addToBackStack(null)
.commit();
break;
case 3: //settings //todo
break;
}
}
@Override
public void onBackPressed() {
if (mNavigationDrawerFragment.isDrawerOpen())
mNavigationDrawerFragment.closeDrawer();
else
super.onBackPressed();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (!mNavigationDrawerFragment.isDrawerOpen()) {
// Only show items in the action bar relevant to this screen
// if the drawer is not showing. Otherwise, let the drawer
// decide what to show in the action bar.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
PrefsFragment fragment = new PrefsFragment();
android.app.FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, fragment)
.addToBackStack(null)
.commit();
return true;
}
return super.onOptionsItemSelected(item);
}
public static class PrefsFragment extends PreferenceFragment {
private final static String TAG = "PrefsFragment";
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getPreferenceManager().setSharedPreferencesMode(MODE_WORLD_READABLE);
addPreferencesFromResource(R.xml.prefs);
}
}
public static class PrefsFragment2 extends PreferenceFragment {
private final static String TAG_2 = "PrefsFragment2";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.prefs2);
}
}
}
93Akkord said:
So.. I stayed up all night and finally got XSharedPreferences to work with my module. But today when I tried to add other elements such as a Navigation Drawer, and have the preference page only show when tapped, it stopped working.
This is the MainActivity code that has been working just fine.
Working:
Code:
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null)
getFragmentManager().beginTransaction().replace(android.R.id.content, new PrefsFragment()).commit();
}
public static class PrefsFragment extends PreferenceFragment {
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getPreferenceManager().setSharedPreferencesMode(MODE_WORLD_READABLE);
addPreferencesFromResource(R.xml.prefs);
}
}
}
Below is the code where it stopped working. I tried back tracking and only with the code above does it work.
Not working:
Code:
public class MainActivity extends AppCompatActivity implements NavigationDrawerCallbacks {
/**
* Fragment managing the behaviors, interactions and presentation of the navigation drawer.
*/
private NavigationDrawerFragment mNavigationDrawerFragment;
private Toolbar mToolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
setSupportActionBar(mToolbar);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getFragmentManager().findFragmentById(R.id.fragment_drawer);
// Set up the drawer.
mNavigationDrawerFragment.setup(R.id.fragment_drawer, (DrawerLayout) findViewById(R.id.drawer), mToolbar);
// populate the navigation drawer
mNavigationDrawerFragment.setUserData("John Doe", "[email protected]", BitmapFactory.decodeResource(getResources(), R.drawable.avatar));
}
@Override
public void onNavigationDrawerItemSelected(int position) {
Fragment fragment;
switch (position) {
case 0: //search//todo
break;
case 1: //Minor theme fixes
fragment = getFragmentManager().findFragmentByTag(PrefsFragment.TAG);
if (fragment == null) {
fragment = new PrefsFragment();
}
android.app.FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, fragment, PrefsFragment.TAG)
.addToBackStack(null)
.commit();
break;
case 2: //Full themed apps
fragment = getFragmentManager().findFragmentByTag(PrefsFragment2.TAG_2);
if (fragment == null) {
fragment = new PrefsFragment2();
}
android.app.FragmentManager fragmentManager1 = getFragmentManager();
fragmentManager1.beginTransaction()
.replace(R.id.container, fragment, PrefsFragment2.TAG_2)
.addToBackStack(null)
.commit();
break;
case 3: //settings //todo
break;
}
}
@Override
public void onBackPressed() {
if (mNavigationDrawerFragment.isDrawerOpen())
mNavigationDrawerFragment.closeDrawer();
else
super.onBackPressed();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (!mNavigationDrawerFragment.isDrawerOpen()) {
// Only show items in the action bar relevant to this screen
// if the drawer is not showing. Otherwise, let the drawer
// decide what to show in the action bar.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
PrefsFragment fragment = new PrefsFragment();
android.app.FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, fragment)
.addToBackStack(null)
.commit();
return true;
}
return super.onOptionsItemSelected(item);
}
public static class PrefsFragment extends PreferenceFragment {
private final static String TAG = "PrefsFragment";
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getPreferenceManager().setSharedPreferencesMode(MODE_WORLD_READABLE);
addPreferencesFromResource(R.xml.prefs);
}
}
public static class PrefsFragment2 extends PreferenceFragment {
private final static String TAG_2 = "PrefsFragment2";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.prefs2);
}
}
}
Click to expand...
Click to collapse
Well.. seems like moving the code that worked to its own activity and the following to the mainactivities oncreate has done the trick.
Code:
pref = getSharedPreferences(getPackageName() + "_preferences", MODE_WORLD_READABLE);
I am unable to get XSharedPreferences to work and the standard shared preferences work perfectly. I create a shared preferences file elsewhere in the application. The file is in the shared_pref folder and I can read the file which is perfectly OK.
However, I cannot make the XSharedPreferences work, I. e. I have the opposite problem.
Therefore, can I ask you to provide the code or a guidance how to make the XSharedPreferences work, so I can read the file inside of the Xposed module? In case you do not want to publish anything in this topic, can you please, send a message?

Onclock property

Can set an oncick listener via this property or not?
I have tried this: androidnClick="@string/str_onclick_searchbt"
where str_onclick_searchbt = "onClickSearch" corresponding to a function onClickSearch(View view).
But it does not seem to be working - my app seems to crash.
If you can't do this then what is the onclick property for?
Change to anonymous onclick listener
I have changed my code to implement the onclick listener on onCreate rather than through the onclick button property.
But still my app seems to crash due to the highlighted code. If I comment it out my app starts up as expected but does not respond to button clicks.
So what I am doing wrong?
Code:
public class HexapodControls extends Activity
{
BluetoothAdapter m_BTAdapter;
BroadcastReceiver m_BTReceiver;
ArrayAdapter<String> m_BTArrayAdapter;
@Override
protected void onCreate(Bundle savedInstanceState)
{
final Button buttonConnectBT = (Button)findViewById(id.button_connectbt);
final Button buttonDisconnectBT = (Button)findViewById(id.button_disconnectbt);
final Button buttonSearchBT = (Button)findViewById(id.button_searchbt);
final Button spinnerBT = (Button)findViewById(id.spinner_bluetooth);
final AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("In onCreate(...)");
alertDialog.setMessage("Search button clicked...");
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", (DialogInterface.OnClickListener) null);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hexapod_controls);
getBluetoothDevices();
[B]buttonSearchBT.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
spinnerBT.setEnabled(false);
buttonConnectBT.setEnabled(false);
buttonDisconnectBT.setEnabled(false);
alertDialog.show();
if (m_BTAdapter.isDiscovering())
m_BTAdapter.cancelDiscovery();
m_BTAdapter.startDiscovery();
}
});[/B]
/*
buttonConnectBT.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view)
{
buttonConnectBT.setEnabled(false);
buttonDisconnectBT.setEnabled(true);
}
});
buttonDisconnectBT.setOnClickListener(
new View.OnClickListener()
{
@Override
public void onClick(View view)
{
buttonConnectBT.setEnabled(true);
buttonDisconnectBT.setEnabled(false);
}
});
*/
}

Pass variable from one activity to another

I want to show the result activity on the end of the quiz which is working. And then show the scores activity on press of a button on the main activity
Advice I got is to Create a listener for the scores button on Main Activity and add code to launch the Scores Activity with an intent where you pass the score. And then retrieve the bundle on the onCreate method on your ScoresActivity. Can someone help me on this please regarding the code.
MainActivity:
Code:
package app.mobiledevicesecurity;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
DatabaseHelper myDb;
private static Button readbtn;
private static Button quizbtn;
private static Button scoresbtn;
private static Button settingsbtn;
private static Button helpbtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myDb = new DatabaseHelper(this);
myDb.insertData();
OnClickReadButtonListener();
OnClickQuizButtonListener();
OnClickScoresButtonListener();
OnClickSettingsButtonListener();
OnClickHelpButtonListener();
}
public void OnClickReadButtonListener() {
readbtn = (Button) findViewById(R.id.readbutton);
readbtn.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("app.mobiledevicesecurity.Read_Category");
startActivity(intent);
}
}
);
}
public void OnClickQuizButtonListener() {
quizbtn = (Button) findViewById(R.id.quizbutton);
quizbtn.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("app.mobiledevicesecurity.Quiz");
startActivity(intent);
}
}
);
}
public void OnClickScoresButtonListener() {
scoresbtn = (Button) findViewById(R.id.scoresbutton);
scoresbtn.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("app.mobiledevicesecurity.Scores");
startActivity(intent);
}
}
);
}
public void OnClickSettingsButtonListener() {
settingsbtn = (Button) findViewById(R.id.settingsbutton);
settingsbtn.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("app.mobiledevicesecurity.Settings");
startActivity(intent);
}
}
);
}
public void OnClickHelpButtonListener() {
helpbtn = (Button) findViewById(R.id.helpbutton);
helpbtn.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("app.mobiledevicesecurity.Help");
startActivity(intent);
}
}
);
}
@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_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Result:
Code:
package app.mobiledevicesecurity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Result extends Activity {
private static Button playbtn;
private static Button menubutton;
int score;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
OnClickPlayButtonListener();
OnClickMenuButtonListener();
TextView textResult = (TextView) findViewById(R.id.textResult);
Bundle b = getIntent().getExtras();
score = b.getInt("score");
textResult.setText("You scored" + " " + score + " for the quiz.");
}
public void getScore()
{
Intent intent2 = new Intent(Result.this,
Scores.class);
Bundle bun = new Bundle();
bun.putInt("score", score);
intent2.putExtras(bun);
startActivity(intent2);
finish();
}
public void OnClickPlayButtonListener() {
playbtn = (Button) findViewById(R.id.btn);
playbtn.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("app.mobiledevicesecurity.Quiz");
startActivity(intent);
}
}
);
}
public void OnClickMenuButtonListener() {
menubutton = (Button) findViewById(R.id.menubtn);
menubutton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
}
);
}
}
Scores:
Code:
package app.mobiledevicesecurity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.content.Intent;
public class Scores extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scores);
Result res = new Result();
res.getScore();
TextView txtScore1 = (TextView) findViewById(R.id.txtScore1);
Bundle bun = getIntent().getExtras();
int score = bun.getInt("score");
txtScore1.setText("Last quiz score:" + " " + score + ".");
}
@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_scores, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
You should never create instances of activity with "new" keyword, because Activity is a part of Android ecosystem, not just a java class. So the line with
Code:
new Result();
is wrong. Then, if you want to pass some data from one activity to another when the latter is being opened after click, you need to put you data in the Intent (like you did it right, but in the wrong place in code)
Code:
scoresbtn.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent2 = new Intent(Result.this,
Scores.class);
Bundle bun = new Bundle();
bun.putInt("score", score);
intent2.putExtras(bun);
startActivity(intent2);
}
}
);
That's it, your code on fetching the "score" variable out of Intent in Score activity is seemingly right.
svvorf said:
You should never create instances of activity with "new" keyword, because Activity is a part of Android ecosystem, not just a java class. So the line with
Code:
new Result();
is wrong. Then, if you want to pass some data from one activity to another when the latter is being opened after click, you need to put you data in the Intent (like you did it right, but in the wrong place in code)
Code:
scoresbtn.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent2 = new Intent(Result.this,
Scores.class);
Bundle bun = new Bundle();
bun.putInt("score", score);
intent2.putExtras(bun);
startActivity(intent2);
}
}
);
That's it, your code on fetching the "score" variable out of Intent in Score activity is seemingly right.
Click to expand...
Click to collapse
Can you maybe show me where to put this in my code. And help me with the new Result() part

user input from a edittext to another activity as normal textview with buttonclick

Hello, I need help for a little project
I have a TextView and a Button in the MainActivity, and an EditText and Button in Activity2 which returns back to MainActivity.
I can switch to the other Activity but I can't send the input of the user in Activity2 back as TextView.
I think there is a problem with the method addListenerOnButton but I'm not sure...
MainActivity:
Code:
public class MainActivity extends Activity {
public TextView resultText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
resultText = (TextView) findViewById(R.id.resultText);
// resultText.setText(getIntent().getStringExtra(""));
}
public void onStartButtonClick(View view){
Intent intent = new Intent(this, Activity2.class);
startActivity(intent);
}
}
Activity2:
Code:
public class Activity2 extends Activity {
public EditText editText;
Button zuruckButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_2);
addListenerOnButton();
editText = (EditText) findViewById(R.id.editText);
}
public void addListenerOnButton(){
zuruckButton = (Button) findViewById(R.id.zuruckButton);
zuruckButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
EditText editText = (EditText) findViewById(R.id.editText);
String text = editText.getText().toString();
Intent intent2 = new Intent(view.getContext(), MainActivity.class);
intent2.putExtra("mein Text", text);
startActivity(intent2);
}
});
}
}
mina2005 said:
Hello, I need help for a little project
I have a TextView and a Button in the MainActivity, and an EditText and Button in Activity2 which returns back to MainActivity.
I can switch to the other Activity but I can't send the input of the user in Activity2 back as TextView.
I think there is a problem with the method addListenerOnButton but I'm not sure...
MainActivity:
Code:
public class MainActivity extends Activity {
public TextView resultText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
resultText = (TextView) findViewById(R.id.resultText);
// resultText.setText(getIntent().getStringExtra(""));
}
public void onStartButtonClick(View view){
Intent intent = new Intent(this, Activity2.class);
startActivity(intent);
}
}
Activity2:
Code:
public class Activity2 extends Activity {
public EditText editText;
Button zuruckButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_2);
addListenerOnButton();
editText = (EditText) findViewById(R.id.editText);
}
public void addListenerOnButton(){
zuruckButton = (Button) findViewById(R.id.zuruckButton);
zuruckButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
EditText editText = (EditText) findViewById(R.id.editText);
String text = editText.getText().toString();
Intent intent2 = new Intent(view.getContext(), MainActivity.class);
intent2.putExtra("mein Text", text);
startActivity(intent2);
}
});
}
}
Click to expand...
Click to collapse
Where your
Code:
editText = (EditText) findViewById(R.id.editText);
is, you can delete this as you are referencing it in your button click method. Unless you are using it for anything else then this can be removed.
Also where
Code:
// resultText.setText(getIntent().getStringExtra(""));
is, this can be uncommented and at the end in brackets of
Code:
getStringExtra("")
is, you should put the extra string you stated as
Code:
intent2.putExtra("mein Text", text);
"mein Text" and put this in the empty
Code:
getStringExtra("")
.
The getStringExtra is is getting the value you put in as text with the key name of "mein Text". So when you call getStringExtra it's saying we will get the value of a string by the name of "mein Text" to identify it and return it.
If this was blank it would not have a name to reference a value to.
Hope this helped i'm new to this as well and hope this is OK for you.
yesss
philnewby2012 said:
Where your
Code:
editText = (EditText) findViewById(R.id.editText);
is, you can delete this as you are referencing it in your button click method. Unless you are using it for anything else then this can be removed.
Also where
Code:
// resultText.setText(getIntent().getStringExtra(""));
is, this can be uncommented and at the end in brackets of
Code:
getStringExtra("")
is, you should put the extra string you stated as
Code:
intent2.putExtra("mein Text", text);
"mein Text" and put this in the empty
Code:
getStringExtra("")
.
The getStringExtra is is getting the value you put in as text with the key name of "mein Text". So when you call getStringExtra it's saying we will get the value of a string by the name of "mein Text" to identify it and return it.
If this was blank it would not have a name to reference a value to.
Hope this helped i'm new to this as well and hope this is OK for you.
Click to expand...
Click to collapse
thank youuuuu that was what i needed! :good:

Share on "Messenger"...

Hi, i made the aplication wher u have buttons.
Oneclick button = play music
LongClick button=Open ContextMenu
In cotextMenu i have 3 buttons, i need to add action for that buttons.
first Button -Share this music on "Messenger"
second Button-Save music to file
third Button-Change as rington
Do you know how look's code to this ^ action?
Java code:
Code:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Button contextMenuButton = (Button) findViewById(R.id.smiech);
registerForContextMenu(contextMenuButton);
final MediaPlayer smiech = MediaPlayer.create(this, R.raw.smiech);
Button playsmiech = (Button) this.findViewById(R.id.smiech);
playsmiech.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
smiech.start();
}
});
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
getMenuInflater().inflate(R.menu.menu_main,menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.item_option1:
break;
case R.id.item_option2:
break;
case R.id.item_option3:
break;
}
return super.onContextItemSelected(item);
}
I saw it in this app: https://play.google.com/store/apps/details?id=com[/url] .morchv.stonoga
Can You help me?

Categories

Resources