Created
May 1, 2018 14:47
-
-
Save Younes-Charfaoui/e395d58e6d67c82edf3a26ca1a99df95 to your computer and use it in GitHub Desktop.
TP of Adda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.charfaoui.tpevaluation; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.util.Log; | |
import android.view.Menu; | |
import android.view.MenuItem; | |
import android.view.ViewGroup; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.LinearLayout; | |
import android.widget.ListView; | |
import android.widget.ScrollView; | |
import android.widget.SimpleAdapter; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
public class MainActivity extends AppCompatActivity { | |
HashMap<String, String> map; | |
SimpleAdapter adapter; | |
private ArrayList<HashMap<String, String>> items; | |
private ListView listView; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
getMenuInflater().inflate(R.menu.menu_main, menu); | |
return super.onCreateOptionsMenu(menu); | |
} | |
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
if (item.getItemId() == R.id.hello) { | |
items = new ArrayList<>(); | |
map = new HashMap<>(); | |
ScrollView scrollView = new ScrollView(this); | |
LinearLayout linearLayout = new LinearLayout(this); | |
linearLayout.setOrientation(LinearLayout.VERTICAL); | |
scrollView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, | |
ViewGroup.LayoutParams.MATCH_PARENT)); | |
linearLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT | |
, ViewGroup.LayoutParams.WRAP_CONTENT)); | |
EditText matricule = new EditText(this); | |
matricule.setHint("Matricule"); | |
matricule.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, | |
ViewGroup.LayoutParams.WRAP_CONTENT)); | |
EditText nom = new EditText(this); | |
nom.setHint("Nom"); | |
nom.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, | |
ViewGroup.LayoutParams.WRAP_CONTENT)); | |
EditText prenom = new EditText(this); | |
prenom.setHint("Prenom"); | |
prenom.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, | |
ViewGroup.LayoutParams.WRAP_CONTENT)); | |
EditText note = new EditText(this); | |
note.setHint("Note"); | |
note.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, | |
ViewGroup.LayoutParams.WRAP_CONTENT)); | |
map.put("mat", "Matricule"); | |
map.put("nom", "Nom"); | |
map.put("prenom", "Prenom"); | |
map.put("note", "Note"); | |
LinearLayout buttonsLayout = new LinearLayout(this); | |
buttonsLayout.setOrientation(LinearLayout.HORIZONTAL); | |
Button afficher = new Button(this); | |
Button anuller = new Button(this); | |
afficher.setText("Afficher"); | |
anuller.setText("Anuller"); | |
afficher.setOnClickListener(v -> { | |
map = new HashMap<>(); | |
map.put("mat", matricule.getText().toString()); | |
map.put("nom", nom.getText().toString()); | |
map.put("prenom", prenom.getText().toString()); | |
map.put("note", note.getText().toString()); | |
Log.i("Tag", "onClick: " + map); | |
items.add(map); | |
// SimpleAdapter adape = new SimpleAdapter(MainActivity.this, items, | |
// R.layout.item_list, | |
// new String[]{"mat", "nom", "prenom", "note"}, | |
// new int[]{R.id.matricule, R.id.nom, R.id.prenom, R.id.note}); | |
adapter.notifyDataSetChanged(); | |
listView.setAdapter(adapter); | |
}); | |
Button he = findViewById(R.id.nouveau); | |
buttonsLayout.addView(afficher); | |
buttonsLayout.addView(anuller); | |
linearLayout.addView(matricule); | |
linearLayout.addView(nom); | |
linearLayout.addView(prenom); | |
linearLayout.addView(note); | |
linearLayout.addView(buttonsLayout); | |
listView = new ListView(this); | |
items.add(map); | |
adapter = new SimpleAdapter(this, items, R.layout.item_list, | |
new String[]{"mat", "nom", "prenom", "note"}, new int[]{R.id.matricule, | |
R.id.nom, R.id.prenom, R.id.note}); | |
listView.setAdapter(adapter); | |
linearLayout.addView(listView); | |
scrollView.addView(linearLayout); | |
setContentView(scrollView); | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment