1
Guys, here’s the deal. I would like to know how to add a paragraph or a single word to a textview that already contains content without necessarily copying what it already has in it. I’d like you to show me something that fits any text.
An example of exactly what I want:
If the checkbox is checked the displayed text is "Neo is". Otherwise "Neo is not".
As I click on the "+1" button I wish it to be added after the content already existing in textview (Neo is/Neo is not) the status corresponding to the value of the cont variable.
If cont == 1 => existing text + unmarried. If cont == 2 => existing text + dating. If cont == 3 => existing text + married.
package genesysgeneration.wwww;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private TextView tv01;
private Button btnMais1;
private int cont=0;
private CheckBox cbNeo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv01=(TextView)findViewById(R.id.tv01);
addCheckBoxCondiction();
addComplementText();
btnMais1=(Button)findViewById(R.id.btnMais1);
btnMais1.setOnClickListener(this);
}
public void addCheckBoxCondiction(){
cbNeo=(CheckBox)findViewById(R.id.cbNeo);
cbNeo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(((CheckBox)v).isChecked()){
tv01.setText(String.valueOf("Neo está"));
}else{
tv01.setText(String.valueOf("Neo não está"));
}
}
});
}
public void addComplementText(){
if(cont==1){
//tv01 => texto já existente + solteiro
}
if(cont==2){
//tv01 => texto já existente + namorando
}
if(cont==3){
//tv01 => texto já existente + casado
}
}
public void onClick(View v){
cont+=1;
}
}
That’s exactly what I want to do. I wish to realize the concatenation of this String.
– Boneco Sinforoso
@Puppeteer if this is what you needed, accept the answer so that in the future other people know that this is the solution.
– leofontes