I passed the data from the first actvity (like int VNIMANI and int OBRATNOST). This data set my TextView after I came on second activity. now I need a button. And when I click on the button I need increment +1. But the code doesn't work.
TextView tvPaklic = (TextView) findViewById(R.id.paklic);
String paklic = String.valueOf( + 10+ (VNIMANI+OBRATNOST));
tvPaklic.setText(paklic);
}
int newPaklic = 0;
public void plusPaklic (View v){
newPaklic = newPaklic + 1;
displayPaklicDve (newPaklic);
}
private void displayPaklicDve(int newPaklic) {
TextView tvpaklicdve = (TextView) findViewById(R.id.paklic);
String paklicdve = String.valueOf(newPaklic);
tvpaklicdve.setText(paklicdve);
}
I would really like to suggest you refer this one Read this, will solve your problem
You were used 2 Textview objects with referring one id check that.
TextView tvPaklic = (TextView) findViewById(R.id.paklic);
TextView tvpaklicdve = (TextView) findViewById(R.id.paklic);
Related
I'm a beginner in android developement and I want to build a small app that gives you the possibility to show the values of an Array into the TextView but I want it to show one value and then it disappears then the second value disappears and so on. This will happen after the onClick() method.
This is my Java Code :
public void GetMyIdea(View view) {
String testatrix[]={"a","s","d", "f","g"};
TextView tv = (TextView) findViewById(R.id.tv);
for(int l=0; l<1; l++){
tv.append(testatrix[l]);
}
}
String testatrix[]={"a","s","d", "f","g"};
int i=0;
TextView tv = (TextView) findViewById(R.id.tv);
public void showText(){
tv.setText(testatrix[i]);
i++;
if(i>4){
i=0;
}
}
Call showText on click
I'm a beginner in android development and I want to build a small App that give you the possibility to show the values of an array into the text view but I want it to show one and then diapers that the second value then diapers .... that will happen after the onClick method :
This is my Java Code :
public void GetMyIdea(View view) {
String testatrix[]={"a","s","d", "f","g"};
TextView tv = (TextView) findViewById(R.id.tv);
for(int l=0; l<1; l++){
tv.append(testatrix[l]);
}
}
this code to me the all values of the array at ones ... I want to show one than the next one then the next one .....
I want to the execution of this code be like that :
1- you enter on the app.
2- you click on the button.
3- than you see in the screen the fist value "a".
4- then you press the button again.
5- the first value "a" will be clean and you see the second value "b".
.
.
. again and again...
1.oncreate {GetMyIdea(null);}
2. btn click call GetMyIdea(view);
int index=0;
public void GetMyIdea(View view) {
String testatrix[]={"a","s","d", "f","g"};
TextView tv = (TextView) findViewById(R.id.tv);
tv.setText(testatrix[index]);
if(index>=testatrix.length){
index=0;
}
else{
index+=1;
}
}
Do like this below. Now whenever you click the button the text has been displayed as per the index of your array
int i = 0;
public void GetMyIdea(View view) {
String testatrix[]={"a","s","d", "f","g"};
TextView tv = (TextView) findViewById(R.id.tv);
tv.setText(testatrix[i]);
i+=1; //Incrementing the value by l
if(i >= testatrix.length){
i = 0;
}
}
I have this piece of code:
public void ON_function(View view) {
int position = lv.getPositionForView(view);
String pozycja = Integer.toString(position);
String tile_content = listaurzadzen.get(position).toString().replace("{urzadzenie=", "\0").replace("}", "\0");
String[] IP_substring = tile_content.split("\r\n");
SendMessage(IP_substring[1].trim(), "switchon");
//ImageButton bulb = (ImageButton)findViewById(R.id.imageButton);
//bulb.setImageResource(R.drawable.bulb_on);
}
public void OFF_function(View view) {
int position = lv.getPositionForView(view);
String pozycja = Integer.toString(position);
String tile_content = listaurzadzen.get(position).toString().replace("{urzadzenie=", "\0").replace("}", "\0");
String[] IP_substring = tile_content.split("\r\n");
SendMessage(IP_substring[1].trim(), "switchoff");
//ImageButton bulb = (ImageButton)findViewById(R.id.imageButton);
//bulb.setImageResource(R.drawable.bulb_off);
}
Two simple functions which are called from dynamically created listview rows, each sends a message or whatever.
My problem is, if I can get the position using (view) to get the string of specific row, why can't I use it to change the image button resource of this specific row? Do I really have to create all these getView methods to make it happen? If so how do I do it with a simple adapter. I have been looking for a solution for a long time.
Can you do
ImageButton bulb = (ImageButton) view.findViewById(R.id.imageButton);
bulb.setImageResource(R.drawable.bulb_off);
my problem is something I've never seen before...
I'm trying to make an android app, and I've stuck at one small bug, and this one is very tricky.
I have 20 TextViews, 10 medium size and 10 regular size, the little ones.
And somehow two of these textviews, one medium and the other is a little one, change it's text one for another. The first should show a text and the second a number. Somehow they are inverse, and I keep looking at the code, and I can't figure out why.
Some of you are thinking that is a simple thing to solve, that I've just misplace the codes, but I'll tell, I've checked over and over again, and it seens right.
public void showWritings(){
TextView tv1stSpentReportM = (TextView) findViewById(R.id.tv1stSpentReportM);
tv1stSpentReportM.setText(vetorGastos[9].getTipoGasto());
TextView tv2stSpentReportM = (TextView) findViewById(R.id.tv2stSpentReportM);
tv2stSpentReportM.setText(vetorGastos[8].getTipoGasto());
TextView tv3stSpentReportM = (TextView) findViewById(R.id.tv3stSpentReportM);
tv3stSpentReportM.setText(vetorGastos[7].getTipoGasto());
TextView tv4stSpentReportM = (TextView) findViewById(R.id.tv4stSpentReportM);
tv4stSpentReportM.setText(vetorGastos[6].getTipoGasto());
TextView tv5stSpentReportM = (TextView) findViewById(R.id.tv5stSpentReportM);
tv5stSpentReportM.setText(vetorGastos[5].getTipoGasto());
TextView tv6stSpentReportM = (TextView) findViewById(R.id.tv6stSpentReportM);
tv6stSpentReportM.setText(vetorGastos[4].getTipoGasto());
TextView tv7stSpentReportM = (TextView) findViewById(R.id.tv7stSpentReportM);
tv7stSpentReportM.setText(vetorGastos[3].getTipoGasto());
TextView tv8stSpentReportM = (TextView) findViewById(R.id.tv8stSpentReportM);
tv8stSpentReportM.setText(vetorGastos[2].getTipoGasto());
TextView tv9stSpentReportM = (TextView) findViewById(R.id.tv9stSpentReportM);
tv9stSpentReportM.setText(vetorGastos[1].getTipoGasto());
TextView tv10stSpentReportM = (TextView) findViewById(R.id.tv10stSpentReportM);
tv10stSpentReportM.setText(vetorGastos[0].getTipoGasto());
TextView tv1stSpentReportV = (TextView) findViewById(R.id.tv1stSpentReportV);
tv1stSpentReportV.setText(String.valueOf(vetorGastos[9].getValorGasto()));
TextView tv2stSpentReportV = (TextView) findViewById(R.id.tv2stSpentReportV);
tv2stSpentReportV.setText(String.valueOf(vetorGastos[8].getValorGasto()));
TextView tv3stSpentReportV = (TextView) findViewById(R.id.tv3stSpentReportV);
tv3stSpentReportV.setText(String.valueOf(vetorGastos[7].getValorGasto()));
TextView tv4stSpentReportV = (TextView) findViewById(R.id.tv4stSpentReportV);
tv4stSpentReportV.setText(String.valueOf(vetorGastos[6].getValorGasto()));
TextView tv5stSpentReportV = (TextView) findViewById(R.id.tv5stSpentReportV);
tv5stSpentReportV.setText(String.valueOf(vetorGastos[5].getValorGasto()));
TextView tv6stSpentReportV = (TextView) findViewById(R.id.tv6stSpentReportV);
tv6stSpentReportV.setText(String.valueOf(vetorGastos[4].getValorGasto()));
TextView tv7stSpentReportV = (TextView) findViewById(R.id.tv7stSpentReportV);
tv7stSpentReportV.setText(String.valueOf(vetorGastos[3].getValorGasto()));
TextView tv8stSpentReportV = (TextView) findViewById(R.id.tv8stSpentReportV);
tv8stSpentReportV.setText(String.valueOf(vetorGastos[2].getValorGasto()));
TextView tv9stSpentReportV = (TextView) findViewById(R.id.tv9stSpentReportV);
tv9stSpentReportV.setText(String.valueOf(vetorGastos[1].getValorGasto()));
TextView tv10stSpentReportV = (TextView) findViewById(R.id.tv10stSpentReportV);
tv10stSpentReportV.setText(String.valueOf(vetorGastos[0].getValorGasto()));
}
}
the Medium TextViews has a M in their names, and the little ones has a V.
In the variable and in the id.
The tv2stSpentReportM is showing the text of tv2stSpentReportV and tv2stSpentReportV the text of tv2stSpentReportV.
To make things more clear, here is the code of my "Gastos.class", This one is what I have in the array vetorGastos[].
public class Gastos {
private String tipoGasto;
private double valorGasto;
public String getTipoGasto() {
return tipoGasto;
}
public void setTipoGasto(String tipoGasto) {
this.tipoGasto = tipoGasto;
}
public double getValorGasto() {
return valorGasto;
}
public void setValorGasto(double valorGasto) {
this.valorGasto = valorGasto;
}
}
As I've told you before, and no one believe me, here as printscreen showing you exacly what I've told. The id's are correct. So what now? And disbelievers, thank you for removing reputation points just cause you don't believe. Expand the Image so you could see that the id's are correct.
I already solve this one now, just rewrite ONE of the id's, and it get right. So if it was just a misplaced id, i should rewrite two id's. I don't know why. but it solve the problem.
I've already solve this one now.
I don't know why, but just rewrite ONE of the id's solved the problem.
If it were a misplaced id, I should change two ID's not rewrite one, the same writing.
I have been able to pass data to other activities except this one. Can anyone see what I'm doing wrong. The only error i'm getting is that my TextView showmsg is NOT showing up in the new activity. Does anyone know why?
public class MyScanActivity extends Activity
{
private static final String MY_CARDIO_APP_TOKEN = "NOT THE PROBLEM";
final String TAG = getClass().getName();
private Button scanButton;
private TextView resultTextView;
private Button buttonBack;
private TextView showmsg;
private int MY_SCAN_REQUEST_CODE = 100; // arbitrary int
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.myscan);
Intent in = getIntent();
if (in.getCharSequenceExtra("usr") != null) {
final TextView setmsg = (TextView)findViewById(R.id.showmsg);
setmsg.setText(in.getCharSequenceExtra("usr"));
}
resultTextView = (TextView)findViewById(R.id.resultTextView);
scanButton = (Button)findViewById(R.id.scanButton);
buttonBack = (Button)findViewById(R.id.buttonBack);
showmsg = (TextView) findViewById(R.id.showmsg);
There are not too many options for how your text can be not shown.
You have the view itself messed up: Check this by putting some sample text in the XML file using android:text="TEST" in the TextView showmsg. Your text should appear, unless your text is the wrong color or size, or something else happens to be above it.
You aren't actually finding it with findViewById() (I hope you've double checked that in a debugger) I agree with alex that you might not want R.id.showmsg. Did you mean to put R.id.resultTextView there instead?
Your passed text is not actually coming through. You should do a log statement, like Log.v(TAG, "Passed text is " + in.getCharSequenceExtra("urs")); and make sure the text is actually coming through.
I haven't test it. but i think that is the reason.
change here:
if (in.getCharSequenceExtra("usr") != null) {
final TextView setmsg = (TextView)findViewById(R.id.showmsg);
setmsg.setText(in.getCharSequenceExtra("usr"));
}
with this:
showmsg = (TextView) findViewById(R.id.showmsg);
if (in.getCharSequenceExtra("usr") != null) {
showmsg.setText(in.getCharSequenceExtra("usr"));
}