Problème boutons
bmaxime18
Messages postés
10
Statut
Membre
-
BunoCS Messages postés 16550 Statut Modérateur -
BunoCS Messages postés 16550 Statut Modérateur -
Bonjour,
j'ai un projet d'une application android pour communiquer avec une carte arduino UNO mais le problème c'est que lorsque je crée un bouton, il ne fonctionne pas lorsque le je test. Je clique dessus mais rien ne se passe.
Si vous avez la solution je suis preneur.
Merci
j'ai un projet d'une application android pour communiquer avec une carte arduino UNO mais le problème c'est que lorsque je crée un bouton, il ne fonctionne pas lorsque le je test. Je clique dessus mais rien ne se passe.
Si vous avez la solution je suis preneur.
Merci
A voir également:
- Problème boutons
- A quoi servent les boutons de couleur sur une telecommande - Guide
- Comment réinitialiser un téléphone avec les boutons - Guide
- Application pour reconnaître les boutons - Accueil - Outils
- Comment déverrouiller un samsung avec les boutons - Guide
- La guerre des boutons streaming vf gratuit - Forum Cinéma / Télé
8 réponses
'lut
Je clique dessus mais rien ne se passe.Mais, vois-tu, il serait plus qu'utile que tu nous fournisse ton code, sans ça on ne pourra jamais savoir ce qui cloche...
Hello,
Je n'ai pas forcément envie de télécharger un fichier rar...
Peux-tu poster le code Java de l'Activity et le XML qui lui correspond?
Je n'ai pas forcément envie de télécharger un fichier rar...
Peux-tu poster le code Java de l'Activity et le XML qui lui correspond?
Voici le MainActivity.java
Et le xml qui lui correspond
package com.dfrobot.angelo.blunobasicdemo;
import android.content.Context;
import android.os.Bundle;
import android.content.Intent;
import android.util.Log;
import android.util.LogPrinter;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ScrollView;
import android.widget.TextView;
public class MainActivity extends BlunoLibrary {
private Button buttonScan;
private Button buttonAvance;
private Button buttonSerialSend;
private EditText serialSendText;
private TextView serialReceivedText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
onCreateProcess(); //onCreate Process by BlunoLibrary
serialBegin(115200); //set the Uart Baudrate on BLE chip to 115200
//serialReceivedText=(TextView) findViewById(R.id.serialReveicedText); //initial the EditText of the received data
//serialSendText=(EditText) findViewById(R.id.serialSendText); //initial the EditText of the sending data
buttonAvance = (Button) findViewById(R.id.button_avance);
buttonAvance.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
serialSend("a");
}
});
Button ButtonRecule = (Button) findViewById(R.id.button_recule);
ButtonRecule.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
serialSend("r");
}
});
Button ButtonDroite = (Button) findViewById(R.id.button_droite);
ButtonDroite.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
serialSend("d");
}
});
Button ButtonGauche = (Button) findViewById(R.id.button_gauche);
ButtonGauche.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
serialSend("g");
}
});
buttonScan = (Button) findViewById(R.id.buttonScan); //initial the button for scanning the BLE device
buttonScan.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
buttonScanOnClickProcess(); //Alert Dialog for selecting the BLE device
}
});
}
protected void onResume(){
super.onResume();
System.out.println("BlUNOActivity onResume");
onResumeProcess(); //onResume Process by BlunoLibrary
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
onActivityResultProcess(requestCode, resultCode, data); //onActivityResult Process by BlunoLibrary
super.onActivityResult(requestCode, resultCode, data);
}
@Override
protected void onPause() {
super.onPause();
onPauseProcess(); //onPause Process by BlunoLibrary
}
protected void onStop() {
super.onStop();
onStopProcess(); //onStop Process by BlunoLibrary
}
@Override
protected void onDestroy() {
super.onDestroy();
onDestroyProcess(); //onDestroy Process by BlunoLibrary
}
@Override
public void onConectionStateChange(connectionStateEnum theConnectionState) {//Once connection state changes, this function will be called
switch (theConnectionState) { //Four connection state
case isConnected:
buttonScan.setText("Connected");
break;
case isConnecting:
buttonScan.setText("Connecting");
break;
case isToScan:
buttonScan.setText("Scan");
break;
case isScanning:
buttonScan.setText("Scanning");
break;
case isDisconnecting:
buttonScan.setText("isDisconnecting");
break;
default:
break;
}
}
@Override
public void onSerialReceived(String theString) { //Once connection data received, this function will be called
// TODO Auto-generated method stub
serialReceivedText.append(theString); //append the text into the EditText
//The Serial data from the BLUNO may be sub-packaged, so using a buffer to hold the String is a good choice.
((ScrollView)serialReceivedText.getParent()).fullScroll(View.FOCUS_DOWN);
}
}
Et le xml qui lui correspond
<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"
android:focusable="true"
android:focusableInTouchMode="true">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scrollView"
android:layout_alignParentBottom="true"
android:layout_below="@+id/buttonScan"
android:visibility="gone">
<TextView
android:id="@+id/serialReveicedText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:textSize="10sp"
android:layout_below="@+id/editText2"
android:layout_alignStart="@+id/editText2"
android:layout_alignEnd="@+id/serialSendText"
android:layout_alignParentBottom="true" />
</ScrollView>
<Button
android:id="@+id/buttonSerialSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send Data"
android:layout_centerHorizontal="true"
android:visibility="gone" />
<Button
android:id="@+id/buttonScan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Scan"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true" />
<ImageView
android:layout_width="147dp"
android:layout_height="138dp"
android:id="@+id/flecheRecule"
android:src="@drawable/fleche_gauche"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="138dp"
android:layout_height="147dp"
android:id="@+id/flecheDroite"
android:src="@drawable/fleche_bas"
android:layout_alignParentBottom="true"
android:layout_alignEnd="@+id/flecheGauche" />
<ImageView
android:layout_width="147dp"
android:layout_height="138dp"
android:id="@+id/flecheAvance"
android:src="@drawable/fleche_droite"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true" />
<ImageView
android:layout_width="138dp"
android:layout_height="147dp"
android:id="@+id/flecheGauche"
android:src="@drawable/fleche_haut"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="147dp"
android:visibility="invisible"
android:id="@+id/button_gauche"
android:layout_gravity="center_horizontal|top"
android:layout_alignEnd="@+id/flecheGauche"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="138dp"
android:visibility="invisible"
android:id="@+id/button_recule"
android:layout_gravity="center|bottom"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:layout_alignEnd="@+id/flecheRecule" />
<Button
android:layout_width="wrap_content"
android:layout_height="147dp"
android:visibility="invisible"
android:id="@+id/button_avance"
android:layout_gravity="center_horizontal|top"
android:layout_alignBottom="@+id/flecheAvance"
android:layout_alignParentEnd="true"
android:layout_alignTop="@+id/flecheAvance"
android:layout_alignStart="@+id/flecheAvance" />
<Button
android:layout_width="154dp"
android:visibility="invisible"
android:layout_height="100dp"
android:id="@+id/button_droite"
android:layout_gravity="end|bottom"
android:layout_alignParentStart="true"
android:layout_alignBottom="@+id/flecheDroite"
android:layout_alignEnd="@+id/flecheDroite"
android:layout_alignTop="@+id/flecheDroite" />
</RelativeLayout>
android:visibility="invisible"
C'est normal, ça? Si les boutons sont invisibles, ils ne reçoivent pas les interactions.
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
mais est ce que c'est bien la ligne
pour pouvoir envoyer un message par bluetooth ?
serialSend("g");
pour pouvoir envoyer un message par bluetooth ?
Alors, la "doc sur les méthodes d'Android Studio" ne va pas t'apporter grand-chose. Par contre, la doc sur Android, oui. La voici: https://developer.android.com/index.html
A noter que je ne pense pas que
A noter que je ne pense pas que
serialSend()soit une méthode du Framework mais plutôt de BlunoLibrary
Voici le lien de mon code : http://www.mediafire.com/file/qgyu3ek7v6kx86e/Android.rar/file
Bon. Ça ne me dit pas quel est le bouton qui ne marche pas.... Lequel est censé faire quoi?
Le seul qui fonctionne est le scan car il était déjà présent dans le code