delete the contents of an edittext - java

I have 9 edittext and a button back I look when we click on the button back the content of a selected edittext is delete help me please
back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
et1.addTextChangedListener(this);
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (count == 0) {
//text was deleted.
}
}
}
});

back.setOnClickListener(new View.OnClickListener() {
if(TextUtils.isEmpty(et1.getText().toString()) {
//your first edit text is empty
}
});

Related

How do I print text from EditText to a textview when pressed enter or a button

So I want the text the person wrote in the EditText box to be printed on the screen when pressed enter or clicked on the button.
final TextView txt= findViewById(R.id.empty_text);
Button btn = findViewById(R.id.button_add);
final EditText tst = findViewById(R.id.test_textEdit);
final String value = tst.getText().toString();
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
txt.append(value+"\n");
tst.setText("");
}
});
I think txt.append(value+"\n"); I think I need something that tells the computer to print the text but I don't find one.
value is only set once, and before you assign your ClickListener. Just pull whatever text is present inside your EditText every time onClick() is called.
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
txt.setText(tst.getText().toString());
}
});
Edit: I just realised you were looking to update the TextView on an "Enter" key press as well. For that you can try:
tst.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int id, KeyEvent event) {
if (id == EditorInfo.IME_NULL) {
txt.setText(tst.getText().toString());
return true;
}
return false;
}
});

How to change text in BaseAdapter

I am trying to change the text of button inside onClick() but it's not changing. I have tried the following -
viewHoder.btn_select_qq.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
viewHoder.btn_select.setText("xxxxx");
notifyDataSetChanged();
}
});
How to set it?
Try this -
viewHoder.btn_select_qq.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Button b = (Button) v;
b.setText("xxxxx");
}
});

Android Studio Display Elements of Arraylist on ImageView

I would like to display images that are stored in an arraylist to an imageview.I am using picasso library to store the links.When i press the button next i want the picture to change to the next image.I am using a for loop but i get only the last element.Here is the code:
ImageView image1;
Button bNext,
ArrayList<String>ll=new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fwtografies);
image1=(ImageView)findViewById(R.id.image1);
bNext=(Button)findViewById(R.id.bNext);
ll.add("http://i.imgur.com/QoUeA2I.jpg");
ll.add("http://i.imgur.com/21szRz9.jpg");
ll.add("https://upload.wikimedia.org/wikipedia/en/e/ec/Clip_Poster.jpg");
bBack.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent fwtografiesActivityIntent = new Intent(Fwtografies.this,MainActivity.class);
Fwtografies.this.startActivity(fwtografiesActivityIntent);
}
});
bNext.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
for(int i=0;i<ll.size();i++){
sp(ll.get(i),image1);
}
}
});
bPrevius.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
viewFlipper.showPrevious();
}
});
sp("http://i.imgur.com/gijIKJO.jpg",image1);
//sp("http://i.imgur.com/QoUeA2I.jpg",image2);
//sp("http://i.imgur.com/21szRz9.jpg",image3);
}
public void sp(String a,ImageView b){
Picasso
.with(getApplicationContext())
.load(a)
.into(b);
}}
Everytime you click on Button "bnext" you are going through your whole for-loop and therefore only the last element of your list gets shown. Try:
int i = 0;
bNext.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if(i<ll.size()){
sp(ll.get(i),image1);
i++;
}
}
});
My mistake is that i used for loop where i should use if statment.
This code works for my case:
int i=0; bNext.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//viewFlipper.showNext();
if(i<ll.size()){
sp(ll.get(i),image1);
i++;
}`

Displaying Numbers from onClickListener() Method

I'm looking to display a string of numbers from button clicks in the same TextView field. So far, I'm only able to display one at a time with each press. How can I display all the numbers I click on the same line? My code looks like the following:
one.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Display.setText("1");
}
});
two.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Display.setText("2");
}
});
.
.
.
nine.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Display.setText("9");
}
});
zero.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Display.setText("0");
}
});
How can I get it to where if I press buttons one through three my display will show "123" instead of "1" then "2" then "3" individually?
You can maintain a string variable containing the current numbers being displayed, then append each digit when the button is clicked, and display that.
String digits = "";
one.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
digits += "1";
Display.setText(digits);
}
});
two.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
digits += "2";
Display.setText(digits);
}
});

Getting Data from EditText, RadioButton and Spinner

I search on many websites and many tutorials how can I get the data from editText and radioGroup and spinner DIRECTLY When the user input the data
I tried with this:
MyEditText.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View view, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_ENTER) {
{case1.setName(CaseName.getText().toString());
}
return true;
}
return false;
}
});
but it didn't take the data, I just use button to make that as shown below:
Test.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.cancel1:
try
{
// 1-Name
case1.setName(CaseName.getText().toString());
}catch(Exception e){
}
break;
}
}});
Can anyone explain what shall I use to save the data in Object(case1) directly when the user input it ?
editext.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// s is your text .
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
#Override
public void afterTextChanged(Editable s) {
}
})
for Radio button
checkbox.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks, depending on whether it's now checked
if (((CheckBox) v).isChecked()) {
Toast.makeText(HelloFormStuff.this, "Selected", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(HelloFormStuff.this, "Not selected", Toast.LENGTH_SHORT).show();
}
}
});

Categories

Resources