Vous êtes sur la page 1sur 4

Université Mustapha Stambouli –Mascara-

Département informatique
Module : Développement d’applications Mobiles /3éme informatique Fiche TD n° :05

__________________________________________________________

Exercice N°01 :

La figure 1 présente l’activité d’une apps android qui exécute trois fonctions :
Button Length : Calcul la somme de la longueur des deux mots insérés (exemple : java / php longueur =7)
Button common : Calcul le nombre de caractères en commun entre les deux mots.
Button Clear : Efface le contenu de tous les EditText.

1. Donnez l’organisation en arborescence de l’activité


Présentée dans la figure -1- en utilisant un TableLayout.
2. Donnez le code minimisé de l’activité ?
3. Donnez un exemple de configuration d’un AVD ?
4. Donnez le code java pour les trois fonctions réalisés par
L’application ?

- Figure 1 -
Correction Fiche TD N°5

Exercice N°1 :
1. <?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TableRow>
<TextView
android:layout_height="wrap_content"
android:layout_width="0dp"
android:text="Mot1"
android:padding="3dip"
android:layout_weight="01"/>
<EditText

android:id="@+id/userName"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:padding="3dip"
android:hint="edt1"
android:layout_weight="03"
/>
</TableRow>
<TableRow>
<TextView
android:layout_height="wrap_content"
android:layout_width="0dp"
android:text="Mot 2"
android:padding="3dip"
android:layout_weight="1"/>
<EditText
android:id="@+id/use"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:hint="edt2"
android:layout_weight="03"
android:padding="3dip"
/>
</TableRow>
<TableRow>
<Button
android:id="@+id/loginBtn"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:text="Length"
android:textStyle="bold"
android:layout_weight="01"/>

<Button
android:id="@+id/loginBtn2"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:text="common"
android:textStyle="bold"
android:layout_weight="01"/>

1
</TableRow>
<TableRow>
<TextView
android:layout_height="wrap_content"
android:layout_width="0dp"
android:text="length"
android:padding="3dip"
android:layout_weight="1"/>
<EditText
android:id="@+id/use3"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:hint="edt3"
android:layout_weight="03"
android:padding="3dip"
/>
</TableRow>
<TableRow>
<TextView
android:layout_height="wrap_content"
android:layout_width="0dp"
android:text="common"
android:padding="3dip"
android:layout_weight="1"/>
<EditText
android:id="@+id/use4"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:hint="edt4"
android:layout_weight="03"
android:padding="3dip"
/>
</TableRow>
<TableRow>
<Button
android:id="@+id/loginBtn3"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:text="Clear"
android:textStyle="bold"
android:layout_weight="01"/>
</TableRow>
</TableLayout>

2. Exemple de configuration d’un AVD :


Vesrion OS : Android 8.0 CPU : 1.2GHZ
RAM : 2GB ROM : 16GB

3. Les fonctions en Java :


 Fonction Length :
public void leng (){
String m1=(ED1.getText()).toString();
String m2=(ED2.getText()).toString();

2
int l= m1.length()+m2.length();
String m= String.valueOf(l);
ED3.setText(m);
}
 Fonction Common

public void Common(){


String m1= (ED1.getText()).toString();
String m2= (ED2.getText()).toString();
boolean cp=false;
int comp=0;
String tab[]=new String [m2.length()];int x=0;
for (int i=0;i<m1.length();i++){
for(int j=0;j<m2.length();j++){
if(m1.charAt(i)==m2.charAt(j)){
tab[x]=String.valueOf(m1.charAt(i));
x++;

}
}
for(int i=0;i<x;i++){
for(int j=0;j<x;j++){
if(tab[i]==tab[j] & i!=j){
tab[j]="-1";
}

}
}

for(int i=0;i<x;i++){
if(tab[i]!="-1"){
comp++;
}
}
ED4.setText(comp);
}

 Fonction clear

public void clear (){


ED1.setText(" ");
ED2.setText(" ");
ED3.setText(" ");
ED4.setText(" ");

Vous aimerez peut-être aussi