Hi I want to connect bluetooth and laptop
What I want to do is, send numeric value from android application to Labview program installed in Laptop.
The android program returns value which changes according to the button click.
(When I press up button, value +1).
And I want to send this value to the laptop via bluetooth!.
I was looking for google, stackoverflow and other many communities., I couldn't find any hints or solutions.
package com.u2ring.control;
import com.u2ring.control.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.webkit.*;
public class MainActivity extends Activity implements OnClickListener
{
Button Plus, Minus;
TextView Value;
TextView url;
int score = 0;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Plus = (Button) findViewById(R.id.up);
Minus = (Button) findViewById(R.id.down);
Value = (TextView) findViewById(R.id.number);
String host = getString(R.string.host);
Plus.setOnClickListener(this);
Minus.setOnClickListener(this);
Button bt1 = (Button) findViewById(R.id.button2);
bt1.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
Intent in = new Intent(MainActivity.this,Secondpage.class);
startActivity(in);
}
});};
public void onClick(View v)
{
boolean showText = false;
int id = v.getId();
if (id == R.id.up) {
score++;
showText = true;
} else if (id == R.id.down) {
score--;
showText = true;
} else if (id == R.id.number) {
showText = true;
}
if(showText)
Value.setText(String.valueOf(score));
WebView wv= (WebView) findViewById(R.id.web);
wv.loadUrl("http://10.16.27.184:8080/admin/speed/"+Integer.toString(score));
}
}
There is a nice Bluetooth example with code for LabVIEW and Android on LabVIEW Hacker.
Related
I am Completely new to Android SDK and very new to writing code in general. I have been monkeying with the software and following a tutorial on how to make a login for my app but I just can't seem to get it to work. Below is my .Java Code. I can tell that the error is in line 32-42, I don't know why I it does not detect .settext or .SetOnClickListner. Any help would be great.
package com.example.inventory;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import org.w3c.dom.Text;
public class MainActivity extends AppCompatActivity {
private EditText User;
private EditText Password;
private TextView Info;
private Button Login;
private int counter = 5;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
User = (EditText) findViewById(R.id.etName);
Password = (EditText) findViewById(R.id.etPassword);
Info = (TextView) findViewById(R.id.tvInfo);
Login = (Button) findViewById(R.id.btnLogin);
}
Info.setText("No of attemps remaining: 5");
Login.SetOnClickListener(new View.OnClickListener()
{
#Override
public void onClick (View view){
validate(Name.getText().toString(), Password.getText().toString());
}
};
}
private void validate(String userName, String userPassword) {
if ((userName.equals("Admin")) && (userPassword.equals("Pass"))) {
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(intent);
}else{
counter--;
if (counter== 0){
Login.setEnabled(false);
}
}
}
}
Your .setText() code is outside of the onCreate method. There is not a process to call the .setText() method. Just move the code inside of the bracket above it. Same goes for your OnClickListeners. You were also missing a parenthesis at the close of your OnClickListener.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
User = (EditText) findViewById(R.id.etName);
Password = (EditText) findViewById(R.id.etPassword);
Info = (TextView) findViewById(R.id.tvInfo);
Login = (Button) findViewById(R.id.btnLogin);
Info.setText("No of attemps remaining: 5");
Login.SetOnClickListener(new View.OnClickListener() {
#Override
public void onClick (View view){
validate(Name.getText().toString(), Password.getText().toString());
}
});
}
Hi I want to connect bluetooth and laptop
What I want to do is, send numeric value from android application to Labview program installed in Laptop.
The android program returns value which changes according to the button click.
(When I press up button, value +1).
And I want to send this value to the laptop via bluetooth!.
I was looking for google, stackoverflow and other many communities., I couldn't find any hints or solutions.
package com.u2ring.control;
import com.u2ring.control.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.webkit.*;
public class MainActivity extends Activity implements OnClickListener
{
Button Plus, Minus;
TextView Value;
TextView url;
int score = 0;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Plus = (Button) findViewById(R.id.up);
Minus = (Button) findViewById(R.id.down);
Value = (TextView) findViewById(R.id.number);
String host = getString(R.string.host);
Plus.setOnClickListener(this);
Minus.setOnClickListener(this);
Button bt1 = (Button) findViewById(R.id.button2);
bt1.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
Intent in = new Intent(MainActivity.this,Secondpage.class);
startActivity(in);
}
});};
public void onClick(View v)
{
boolean showText = false;
int id = v.getId();
if (id == R.id.up) {
score++;
showText = true;
} else if (id == R.id.down) {
score--;
showText = true;
} else if (id == R.id.number) {
showText = true;
}
if(showText)
Value.setText(String.valueOf(score));
WebView wv= (WebView) findViewById(R.id.web);
wv.loadUrl("http://10.16.27.184:8080/admin/speed/"+Integer.toString(score));
}
}
You will need to connect the laptop and the phone over bluetooth first either manually or create a service. Android provides access to your phone's Bluetooth through BluetoothAdapter. To access the BluetoothAdapter you will need to add the appropriate permission(for bluetooth) in the manifest file.
You can then manage connections through the different methods of the BluetoothAdapter.For details visit here
I am new to Android and Java and don't know why the Text value is null after I assign Text to it? This is a project for University They didn't teach us Java only gave us Eclipse and Android Sdk and Java need some help please!
package com.example.glossaryapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class Syntax extends Activity {
static String Text;
public static TextItem[] Syntax = new TextItem[50];
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.syntax);
final TextView show = (TextView) Syntax.this
.findViewById(R.id.textViewSyn);
// Linking the text View widget
int Count1 = 0;
// Using the TextView's shows method set text to display the appropriate
// arrays and indexes
if (Syntax[0] != null) {
Text = Syntax[0].displayText();
show.setText(Text);
}
// The Add button for if a user wants to add a new TextItem to the Array
Button but1 = (Button) findViewById(R.id.butAddSyntax);
but1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Create.strSender = "Syntax1";
startActivity(new Intent(Syntax.this, Create.class));
}// end of on click
});// butAddSyntax
// Home Button
Button but2 = (Button) findViewById(R.id.buttHomeSyntax);
but2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
finish();
}// end of on click
});// buttonHomeSyntax
}
public void onResume() {
super.onResume();
TextView show = (TextView) Syntax.this.findViewById(R.id.textViewSyn);
if (Syntax[0] != null) {
Text = Syntax[0].displayText().toString();
show.setText(Text);
}
}
}
Using Android's LogCat will help you to solve this kind of problems.
Here you have a nice article:
http://www.vogella.com/tutorials/AndroidLogging/article.html
I think the problem is in here:
if( Syntax[0] != null ){
Text = Syntax[0].displayText();
show.setText(Text);
}
you could begin using LogCat trying this:
if( Syntax[0] != null ){
Log.d("MyApp", "Sintax (0) = " + Syntax[0].displayText());
Text = Syntax[0].displayText();
show.setText(Text);
} else Log.d("MyApp", "Nothing ");
And watch the result in the Logcat pane.
I want to develop an aptitude app..
for that in my text view i have to display first question .. On clicking next button i have to display second question.. on again clicking same next button third question have to be displayed.. liked that i want to display some 30 questions ..all questions should be displayed in single java file.I Tried to display two questions . but for multiple questions i could not find the code..
package com.example.asl;
import java.util.Arrays;
import java.util.Random;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class Aptitude extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.aptitude);
Button b=(Button) findViewById(R.id.button1);
final TextView tv=(TextView) findViewById(R.id.textView1);
final String Question[]={"what is UR Name","What is ur Age","Whats ur Qualification"};
Button btnNext = (Button) findViewById(R.id.button1);
final TextView cumulos = (TextView) findViewById(R.id.textView1);
//TextView respostas = (TextView)findViewById(R.id.respostas);
Random randPhrase = new Random();
final String[] cum = {"what is UR Name","What is ur Age","Whats ur Qualification"};
//String[] resp = getResources().getStringArray(R.array.resp_cumulos);
String textout = "";
String textresp = "";
//Button btnPrevious = (Button) findViewById(R.id.yourPreviousbutton);
btnNext.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
int i = 0;
if(i<cum.length-1){
i+=1;
cumulos.setText(cum[i]);
// respostas.setText(resp[i]);
}
}
});
//btnPrevious.setOnClickListener(new OnClickListener(){
//public void onClick(View arg0) {
//if(i>0){
// i-=1;
// cumulos.setText(cum[i]);
// respostas.setText(resp[i]);
// }
// }
//});
}
}
enter code here
Initializing your counter in your onClick() is always going to reset it
Initialize it outside of onClick() and increment it in onClick() as you are.
public class Aptitude extends Activity {
int i = 0;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.aptitude);
Button b=(Button) findViewById(R.id.button1);
...
}
public void onClick(View arg0) { // rename arg0 to something meaningful
// like v or view for readibility
// int i = 0; remove this guy
if(i<cum.length-1){
i+=1;
cumulos.setText(cum[i]);
If this doesn't fix your problem then please explain what the problem is but I'm sure this part was causing you trouble.
I'm beginner in android and I wrote the following simple program that just shows the text of the button I press on a TextView (I always get a runtime error):
package com.hmz.secondapp;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class AppPageActivity extends Activity {
Button btnPlus;
Button btnMinus;
Button btnMul;
Button btnDiv;
TextView resultTextView;
View.OnClickListener operations = new View.OnClickListener() {
public void onClick(View v) {
Button pressedButton = (Button) v;
String buttonLabel = pressedButton.getText().toString();
resultTextView.setText(buttonLabel);
}
};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.app_page);
btnPlus.setOnClickListener(operations);
btnMinus.setOnClickListener(operations);
btnMul.setOnClickListener(operations);
btnDiv.setOnClickListener(operations);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.app_page, menu);
return true;
}
}
Your btnPlus object is null. You need to instantiate it in the onCreate method like
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.app_page);
btnPlus = (Button)findViewById(R.id.YOUR_BUTTON_ID);
btnMinus = (Button)findViewById(R.id.YOUR_BUTTON_ID);
btnMul = (Button)findViewById(R.id.YOUR_BUTTON_ID);
btnDiv = (Button)findViewById(R.id.YOUR_BUTTON_ID);
btnPlus.setOnClickListener(operations);
btnMinus.setOnClickListener(operations);
btnMul.setOnClickListener(operations);
btnDiv.setOnClickListener(operations);
}
Also instantiate the resultTextView object before you use setText method.
From your code the problem is seems that you are not initializing the buttons (btnPlus,btnMinus,btnMul,btnDiv) and the TextView resultTextView.
btnPlus = (Button)findViewById(Button Id);
btnMinus = (Button)findViewById(Button Id);
btnMul = (Button)findViewById(Button Id);
btnDiv = (Button)findViewById(Button Id);
resultTextView = (Button)findViewById(TextView Id);
First initialize these Views then you can apply any operation on these views like Click Events and setting the text.