IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Comment obtenir les coordonnées exactes où j'ai touché dans le clavier


Sujet :

Android

  1. #1
    Candidat au Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Juin 2017
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : Maroc

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2017
    Messages : 2
    Points : 3
    Points
    3
    Par défaut Comment obtenir les coordonnées exactes où j'ai touché dans le clavier
    J'ai un edittext, et quand je clique sur ce edittext, un clavier virtuel apparaît, je veux obtenir la position exacte (coordonnées) que j'ai touchée dans le clavier (getX, getY).

    Voici le fichier main.XML:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent" android:id="@+id/xMLayout"
                android:background="#000000" android:layout_height="fill_parent"
                android:focusable="true"
                android:orientation="vertical">
     
                <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    android:layout_width="fill_parent" android:id="@+id/xsubLayout"
                    android:keepScreenOn="true" android:orientation="vertical"
                    android:layout_height="fill_parent">
     
                    <EditText android:id="@+id/xEt" android:layout_width="fill_parent"
                        android:focusableInTouchMode="true" android:layout_height="410sp" />
     
                </RelativeLayout>
     
                <RelativeLayout xmlns:android="http://schemas.andr`enter code here`oid.com/apk/res/android"
                    android:layout_width="match_parent" android:id="@+id/xK1"
                    android:layout_height="wrap_content" android:orientation="vertical"
                    android:visibility="gone">
     
                    <include android:id="@+id/xKeyBoard" layout="@layout/keyboard"></include>
     
                </RelativeLayout>
     
            </RelativeLayout>
    Et voici keyboard.xml:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/hebrwKeyboardView" android:layout_width="fill_parent"
        android:layout_alignParentBottom="true" android:layout_below="@+id/xsubLayout"
        android:orientation="vertical" android:background="#252625"
        android:visibility="visible" android:layout_height="180sp">
     
        <TableLayout
            android:layout_width="fill_parent" android:layout_height="200sp"
            android:orientation="vertical"
            android:clipChildren="true"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true" android:id="@+id/xclavier">
     
            <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="wrap_content" android:layout_height="200sp"
                android:padding="0sp">
     
                <TableRow android:layout_width="fill_parent" ....>
                <TableRow android:layout_width="fill_parent" ....>
                <TableRow android:layout_width="fill_parent" ....>
                <TableRow android:layout_width="fill_parent" ....>
     
            </TableLayout>
        </TableLayout>
    </RelativeLayout>
    Des idées SVP.

    Merci.

  2. #2
    Modérateur
    Avatar de grunk
    Homme Profil pro
    Lead dév - Architecte
    Inscrit en
    Août 2003
    Messages
    6 691
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Lead dév - Architecte
    Secteur : Industrie

    Informations forums :
    Inscription : Août 2003
    Messages : 6 691
    Points : 20 222
    Points
    20 222
    Par défaut
    Si ton objectif est d'avoir les coordonnées X/Y pour faire un clavier custom tu fais fausse route.
    Android propose tout ce qu'il faut pour créer ses propres claviers et donc ne pas avoir à gérer la position des événements.

    https://developer.android.com/guide/...ut-method.html

    Un bon exemple pour réaliser un clavier personnalisé : http://www.fampennings.nl/maarten/an...oard/index.htm
    Pry Framework php5 | N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  3. #3
    Candidat au Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Juin 2017
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : Maroc

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2017
    Messages : 2
    Points : 3
    Points
    3
    Par défaut
    bonjour, j'ai déjà développé un clavier virtuel le problème c'est que je veux lorsque je touche sur ce clavier il me retourne les cordonnées x et y de l'emplacement ou j'ai touché dedans, j'ai bien essayé de créer un lisner (OntouchListner) mais ça marche plus il me retourne rien et voila le code que j'ai utilisé:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    public void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		try {
     
    			setContentView(R.layout.main);
     
                            //Appel aux Fonctions de gestion des boutons du clavier
    			setKeys();
    			setFrow();
    			setSrow();
    			setTrow();
    			setForow();
     
     
    			mEt = (EditText) findViewById(R.id.xEt);
    			mEt.setOnTouchListener(this);
    			mEt.setOnFocusChangeListener(this);
    			mEt.setOnClickListener(this);
     
     
    			mLayout = (RelativeLayout) findViewById(R.id.xK1);
    			mKLayout = (RelativeLayout) findViewById(R.id.xKeyBoard);
     
    			mKLayout.setOnClickListener(this);
    			mKLayout.setOnTouchListener(new OnTouchListener(){
    				public boolean onTouch(View V, MotionEvent event){
    					float x = event.getX();
    					float y = event.getY();
    					System.out.println("xxxxxxx ==> "+x+"   yyyyyyyy ==> "+y);
    					return true;
    				}
    			});
    		} catch (Exception e) {
    			Log.w(getClass().getName(), e.toString());
    		}
     
    	}

Discussions similaires

  1. Réponses: 2
    Dernier message: 14/12/2016, 13h21
  2. Comment obtenir les coordonnées d'une cellule?
    Par Antoine505 dans le forum Excel
    Réponses: 1
    Dernier message: 23/10/2013, 11h55
  3. Obtenir les coordonnées réelles
    Par chep dans le forum OpenGL
    Réponses: 2
    Dernier message: 19/04/2005, 12h05
  4. Comment obtenir les Handles des boutons systèmes de Windows ?
    Par Desraux dans le forum API, COM et SDKs
    Réponses: 6
    Dernier message: 22/12/2004, 22h20
  5. Réponses: 2
    Dernier message: 14/09/2004, 18h00

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo