Alter text textbox Android

  • Replies:7
Pixelayer
  • Forum posts: 3

Aug 26, 2013, 10:09:01 PM via Website

How can I change the text of a textbox when clicking a button?

— modified on Aug 26, 2013, 11:11:30 PM

Reply
Ashish Tripathi
  • Forum posts: 211

Aug 27, 2013, 6:33:27 AM via Website

is it textview or what?

if it is textview than onButton onclick

textview.setBackground();

Reply
Pixelayer
  • Forum posts: 3

Aug 27, 2013, 1:29:37 PM via Website

I have a TextView, I wanted to change the current text that it is (Click) for text (Checked)

Reply
Ashish Tripathi
  • Forum posts: 211

Aug 27, 2013, 2:41:26 PM via Website

i am not sure about ur problem but still see if it can help u

Activity Class

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener {
WifiManager wifiManager;
ConnectivityManager mgr;
Button b;
TextView t;
private BluetoothAdapter mBluetoothAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t = (TextView) findViewById(R.id.textView1);
b = (Button) findViewById(R.id.button1);
b.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.button1:{
t.setText("text Changed");
}
}

}
}


XMl CLass

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginLeft="54dp"
android:layout_marginTop="36dp"
android:text="Button" />

</RelativeLayout>

Reply
Pixelayer
  • Forum posts: 3

Aug 27, 2013, 8:38:32 PM via Website

Now I'm with another doubt.

How can I use IF and ELSE where to receive the letter A Toast by bluetooth exibr one, is equally the letter B shows another Toast. My code does not work.

I am so my code

1byte[] msgBuffer = new byte[1];
2
3int bytes = inStream.read(msgBuffer);
4
5if(new String(msgBuffer) == "a")
6{
7 Toast.makeText(getApplicationContext(), "OK, 0).show();
8}
9else if(new String(msgBuffer) == "b")
10{
11 Toast.makeText(getApplicationContext(), "Error", 0).show();
12}

I did a test using a Toast, where it displays What did this cendo received by bluetooth, and it usually receives, I can receive the letter A and the letter B normally, but the IF and ELSE What do not compare this being received by bluetooth.

Code Test

1Toast.makeText(getApplicationContext(), new String(msgBuffer), 0).show();

Thanks

— modified on Aug 27, 2013, 8:39:11 PM

Reply
Ashish Tripathi
  • Forum posts: 211

Aug 30, 2013, 2:02:59 PM via Website

Hi

Not able to get your issue. Brief more.

Reply
Christian
  • Forum posts: 307

Sep 3, 2013, 10:19:01 AM via Website

Hi Pixelayeren,

in java you compare the value of an String with the function ".equals()" and not with "==".

— modified on Sep 3, 2013, 10:19:47 AM

Reply
kevinv wallace
  • Forum posts: 12

Sep 3, 2013, 11:22:25 AM via Website

Pixelayer
How can I change the text of a textbox when clicking a button?

Hello..



I am agree with Christian Hempe that in java you have to compare the value of an String with the function ".equals()" and not with "==".

Reply