Bonjour à vous,

Grand débutant sous Android, je galère (larmes de sang) pour mettre au point une interface avec quelques widgets

En alternative à l'abandon pur et simple du développement sous Android (un vrai calvaire), je vous soumet ce petit code qui affiche trois boutons avec leurs listeners associés:

Le 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
 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <Button
        android:id="@+id/btnNew"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Nouveau document"
    />    
    <Button
        android:id="@+id/btnOpen"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Fuck the Christ"
    />    
    <Button
        android:id="@+id/btnQuit"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Quitter"
    />    
</LinearLayout>
Le code Java:
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
 
package com.Exo1;
//import static com.Exo1.CallDialogs.*;
 
//import android.view.View.OnClickListener;
//import android.view.View.OnTouchListener;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.MotionEvent;
public class Main extends Activity implements View.OnClickListener, View.OnTouchListener
{
 
    private Button btnNewDoc = null;  
    private Button btnOpen   = null;  
    private Button btnQuit   = null;
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
 
        setContentView(R.layout.main);
 
        btnNewDoc = (Button) findViewById(R.id.btnNew);
        btnOpen   = (Button) findViewById(R.id.btnOpen);
        btnQuit   = (Button) findViewById(R.id.btnQuit);
 
        //btnQuit.setOnClickListener(clickListenerBtnQuit);
        btnNewDoc.setOnClickListener(this);
        btnOpen.setOnClickListener(this);
        btnQuit.setOnClickListener(this);
        btnQuit.setOnTouchListener(this);
        //*/
    }
    //*********************
 
    @Override
    public boolean onTouch (View v, MotionEvent event)
    {
        return true;
    }   
    @Override
    // intercepte tous les événements Click et les ventile vers les composants touchés
    public void onClick(View v)
    {
        switch(v.getId())
        {
            case R.id.btnNew:
                ; // actions bouton Nouveau
                break;
            case R.id.btnOpen:
                ; // actions bouton Ouvrir
                break;
            case R.id.btnQuit:
                ; // actions bouton Quitter
                //AfficherMessage("Bouton Quitter est clické");
                //if (QuestionOuiNon("Quitter")) AfficherMessage("Fin de l'application");
                break;
            default:
                break;
        }    
    } 
    //*/
}
Ce code plante au démarrage ('Unfortunaly, your application has stopped'

Je n'ai que trois jours pour remettre mon étude de faisabilité d'un projet sous Android. aussi, sans aide sous ces trois jours, je jette l'éponge et remets un avis défavorable.

Cdlt.