0% found this document useful (0 votes)
62 views10 pages

Application 2: Listeners/ Animation:: On Utilise Les Listeners Pour Démarrer Des Animations de Widgets

The document discusses using listeners to trigger animations in widgets. It describes retrieving widgets from XML using findViewById, triggering an event when a button is touched using OnTouch, and triggering an event slowly clicking a button. It then discusses using a ListView, Adapter, and Intents to display a list of names and phone numbers from an array and allow clicking an item to open a new activity displaying additional data in a Spinner.

Uploaded by

rhariss97
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views10 pages

Application 2: Listeners/ Animation:: On Utilise Les Listeners Pour Démarrer Des Animations de Widgets

The document discusses using listeners to trigger animations in widgets. It describes retrieving widgets from XML using findViewById, triggering an event when a button is touched using OnTouch, and triggering an event slowly clicking a button. It then discusses using a ListView, Adapter, and Intents to display a list of names and phone numbers from an array and allow clicking an item to open a new activity displaying additional data in a Spinner.

Uploaded by

rhariss97
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Application 2 : Listeners/ Animation :

On utilise les listeners pour démarrer des animations de widgets :

findViewById : Récupérer les


widgets de l’XML à l’aide l’identité
ID.

OnTouch : Déclenché l’événement


quand on touche le button.

Déclencher l’événement lorsqu’on


clique sur le buton lentement

Déclenché l’événement lorsqu’on


clique sur le buton1.
Application 3 : ListeView/adapter :
Application 4 : ListeView/adapter :
XML :
Application 5 : Adapters et Intents
MainActivity :
public class MainActivity extends AppCompatActivity {
ListView listView;
String Name[] = {"Bill Gates", "Niels Bohr", "Azmie Rachid"};
String numTel[] = {"06 06 06 06 06", "06 05 05 05 05", "06 11 11 11 11"};
Button cliquer;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = listView.findViewById();
cliquer= cliquer.findViewById();
MyAdapter adapter = new MyAdapter(this, Name, numTel);
listView.setAdapter(adapter);
cliquer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,ItemActivity.class);
startActivity(intent);
}
});

private void setContentView(int activity_main) {


}

class MyAdapter extends ArrayAdapter<String> {

Context context;
String Name_str[];
String numTel_str[];

MyAdapter (Context c, String Name[], String numTel[]) {


super(c, R.layout.row, R.id.textView1, Name);
this.context = c;
this.Name_str = Name;
this.numTel_str = numTel;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull
ViewGroup parent) {
LayoutInflater layoutInflater =
(LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_S
ERVICE);
View row = layoutInflater.inflate(R.layout.row, parent, false);
TextView Name = row.findViewById(R.id.textView1);
TextView numTel = row.findViewById(R.id.textView2);
Name.setText(Name_str[position]);
numTel.setText(numTel_str[position]);
return row;
}
}
}
SpinnerActivity :
public class ItemActivity extends AppCompatActivity {
Button cliquer;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_item);
cliquer = findViewById(R.id.button);
cliquer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(ItemActivity.this,
SpinnerActivity.class);
startActivity(intent);
}
});
}
}

You might also like