I am a beginning of Android Programming, i am wring a SMS sending program today.
The program like this:
After clicking the Sent button,
The results will shown like above:
But may I shown the results below the send button, like the following one ?
Here is the java code of front page :
public class sms extends Activity {
Button sendButton;
EditText phoneTextField;
EditText msgTextField;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.smslay);
msgTextField = (EditText) findViewById(R.id.msgTextField);
sendButton = (Button) findViewById(R.id.sendButton);
phoneTextField = (EditText) findViewById(R.id.phoneTextField);
}
Just take one textview below to send button. After you got result just set text to that textview. When user will again click on send button set that text to empty string.
It sounds like you want a toast message http://developer.android.com/guide/topics/ui/notifiers/toasts.html
Instead of edittext or vise versa
Related
I have tried to create a button, actually that's what I want. I wish that when the user logs in (Name+number) 2 editTexts, He will be able to start and go to ordering activity. But when he comes turns the app off. he will find the editText hidden and get to signIn again when he presses signIn, please check this picπ. I have actually record signIn to preferences. just want to customise that sign IN buttonππππ
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intro1);
editText = (EditText) findViewById(R.id.signIn);
editText1 = (EditText) findViewById(R.id.myNob);
TextView definingSignIn = findViewById(R.id.definingSignIn);//Just a textView for explaining why we need signIn
TextView definingSignIn = findViewById(R.id.definingSignIn);
TextView signInAgain = findViewById(R.id.signInAgain);
signInAgain.setOnClickListener(view -> {
if (editText.getText().toString().isEmpty()){
editText.setVisibility(View.VISIBLE);
if (editText1.getText().toString().isEmpty())
editText1.setVisibility(View.VISIBLE);
} else {
editText1.setVisibility(View.GONE);
editText.setVisibility(View.GONE);
definingSignIn.setVisibility(View.GONE);
}
});
}
I know there are other questions that have already been asked on this topic and I've already looked through a lot of them and tried their answers but none of them have worked.
I've got 2 activities, MainActivity and Main2Activity (that was the given name) (I'll refer to them as 1 and 2 respectively) each with their own respective XML files. What I'm trying to do is have a user enter something into an EditText field on 2 and then when they press enter, what they entered will appear in a TextView on 1. I'm trying to first get it to work when they press a button but it refuses to work. The ultimate goal is for it to get it to get transferred to 1 when they press/tap the enter key on the keyboard that pops up, so if it's easier to just skip the button and go straight to the enter key then by all means.
Any help that I can get is greatly appreciated. I'll put my (relevant) code as well as a couple screenshots below. Thank you.
Java code for 2 (Main2Activity):
public class Main2Activity extends AppCompatActivity {
EditText et;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
et = (EditText) findViewById(R.id.editText);
}
EditText text;
public void CLICK_THIS (View v)
{
Intent intent = new Intent();
intent.putExtra("TextValue", et.getText().toString());
intent.setClass(Main2Activity.this, MainActivity.class);
startActivity(intent);
}
Intent intent = getIntent(); //i honestly forgot what this line is doing here
//i think it's here from some other thing i was trying to do and i just forgot to delete it.
}
Java code for 1 (MainActivity):
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
view = (ImageView) findViewById(R.id.imageView3);
backgroundImageName = String.valueOf(view.getTag());
TextView text = (TextView) findViewById(R.id.textView2);
String s = getIntent().getStringExtra("TextValuie");
text.setText(s);
}
Screenshot 1 (this is what MainActivity (1) looks like):
The text that's highlighted is just to show where the TextView is. it's "not supposed to be here".
Screenshot 2 (this is what Main2Activity (2) looks like):
Screenshot 3 (this just shows the keyboard) (ultimately the user would type something into the "Enter Your Text Here" and then press the Check mark and it would appear where the highlighted text is in 1 instead of clicking the button in 2 for that to happen). If I've confused anyone at any point please don't hesitate to ask for more information.
First of all you are retrieving the input using a wrong label "TextValuie" instead of "TextValue"
The other thing is that are you entering the text that on Button Click the EditText can get the entered value or the default would be an empty string?
You can always debug and put a break point on the intent to see the data that you are getting back from the activity.
final TextView textView = (TextView) findViewById(R.id.textView);
final EditText editText = (EditText) findViewById(R.id.editText);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String etString = editText.getText().toString();
textView.setText(etString);
}
});
I am new to coding and I don't know how to automatically clear the text in an EditText so the user doesn't have to do it themselves. You can see in all "big" websites that when you enter text into a text box (for example: "What's your name?") you see "first name" in the text box and when you click on it, it disappears. How can I make the text disappear automatically without the user having to delete it manually?
What you're referring to isn't actually text that's being set -- it's a hint (which is why it doesn't show after the EditText is focused or text has already been entered). You can set these placeholder hints in your EditText XML, for example:
android:hint="First Name".
If you're feeling really adventerous, you can also wrap your EditText in a TextInputLayout for a Material Design style floating hint.
If that helps, be sure to accept this answer.
You can do it grammatically by modifying your code to use the hint property:
editText.setText("");
editText.setHint(<string>);
also you can change color by adding
editText.setHintTextColor(<some color>);
i was wondering how can i make a textview viewable where the user can click on it and when he click on it the textview creates another page where the text is by her own and the user can select the textview now, because i have more than 30 textviews and i want to make each of them when they get clicked they have their own layout where user can select them now and add more stuff like sharing the textview and this is all in one layout for each textview alone
i hope you can help me and thanks in advance
Make a new activity and use put/get extra to pass on data to new activity.
try following
http://developer.android.com/training/basics/firstapp/index.html
you should create list view
and in on item click of the list you can simply start another activity which will have layout according to the item you have clicked.
click here
and there onitemclick you can start new activity
Intent intent = new Intent(this, NewActivity.class);
intent.purStringExtra("key",rowItems.get(position));
startActivity(intent);
try it and ask if you have any doubt or it is not clear
You can use this code to make your TextView visible on click event
myTextView.setVisibility(View.VISIBLE);
try using Buttons instead of TextViews for getting TextViews...
example
you have Buttons "A" and "B" and want to show Button "B" only when when A Clicked and then want to show TextView "C" only when when B Clicked
in this way (A->B->C )
then try using these codes:
only important parts are written...
in activity_main.xml :
<Button
android:id="#+id/button_A"
android:onClick="do_A"/>
<Button
android:id="#+id/button_B"
android:onClick="do_B"/>
<TextView
android:id="#+id/Textview_C" />
in MainActivity.java :
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button A = findViewById(R.id.button_A);
Button B = findViewById(R.id.button_B);
TextView C = findViewById(R.id.Textview_C);
B.setVisibility(View.GONE);
C.setVisibility(View.GONE);
}
public void do_A (View v){
B.setVisibility(View.VISIBLE);
}
public void do_B (View v){
C.setVisibility(View.VISIBLE);
}
}
I'm a beginner to Java and I want to validate an EditText. What I have in mind: my editText has to match "helloworld". When you press a button this has to be validated. If this is true--> go to a new class in which I have a setContentView to display a new layout.
If the text which I have just typed does not match "helloworld", it should do nothing. It seems very easy but since I'm a beginner you would help me BIGTIME!
Here's most of the logic handled. You will need to fill in your actual layout id's and make your launch intent. Put this code in your onCreate method in the activity with the layout that contains the edit text box
EditText editText = (EditText)findViewById(R.id.editTextBox);
Button btn = (Button)findViewById(R.id.checkBtn);
btn.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
if(editText.getText().toString().equalsIgnoreCase("helloworld")){
//Launch activity with new view
}
}
});
In an activity (or android class) you have to get the instance of your EditText. Your edit text has an id, and you can get it using R. R is the resources for your app.
EditText t = (EditText)findViewById(R.id.<Name of your textfield>);
Then you can get the value of that textfield and compare it
t.getText().toString().equals("helloworld");
will return true or false. If you dont care about the case of the letters use
t.getText().toString().toLowerCase().equals("helloworld");
you will need an onClickListener for your button, check out the android api
http://developer.android.com/reference/android/view/View.OnClickListener.html
in your onCreate, when declaring your submit button, add a listener
Button submit = (Button) findViewById(R.id.submit);
submit.setOnClickListener(submitListener);
make a new onClick listener and fire an Intent to start a new activity
View.OnClickListener submitListener = new View.OnClickListener() {
public void onClick(View v) {
//if string matches helloworld fire new activity
Intent newActivity = new Intent();
startActivity(newActivity);
}
};
// create a reference to the EditText in your layout
EditText editText = (EditText)findViewById(R.id.editTextIdInLayout);
// create a reference to the check Button in your layout
Button btn = (Button)findViewById(R.id.buttonIdInLayout);
// set up an onClick listener for the button reference
btn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
String userInput = editText.getText().toString(); // get the user input
if (userInput.equals("helloworld") // see if the input is "helloworld"
{
setContentView(R.layout.newLayout); // change the content view
}
}
});