Académique Documents
Professionnel Documents
Culture Documents
Merged 20200602 174019
Merged 20200602 174019
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.
- 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
int l= m1.length()+m2.length();
String m= String.valueOf(l);
ED3.setText(m);
}
Fonction Common
}
}
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