Problème récupération variable
Bonjour la communauté,
voila mon mon problème j ai récupéré un script qui fonctionne bien mais voila : j ai trois classe la premiere la classe Book qui me permet de recuperer mes données, apres j ai un un Userlistadapter pour mettre en forme puis une classe ou je dois récupéré la donnée en fonction du clic et la pas d affichage et aucun problème l application se lance bien. donc je joins le code des trois classe avec les commentaires si quelqu un peu me faire avancer merci car malgré mes cours de base en java je rame grave. merci par avance.
la classe Book:
Code:
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
public class Book implements Comparable<Book> {
public String produits;
public String pci;
public String pvs;
private String massevolumique;
private String densiteair;
private String masse;
private String facteurrtnt;
private String liste;
public Book() {
// TODO Auto-generated constructor stub
}
public Book(String produits, String pci, String pvs, String massevolumique,
String densiteair, String masse, String facteurrtnt, String liste) {
super();
this.produits = produits;
this.pci = pci;
this.pvs = pvs;
this.massevolumique = massevolumique;
this.densiteair = densiteair;
this.masse = masse;
this.facteurrtnt = facteurrtnt;
this.liste = liste;
}
/**
* @return le produit
*/
public String getProduits() {
return produits;
}
/**
* @param title
* the title to set
*/
public void setTitle(String produits) {
this.produits = produits;
}
/**
* @return the author
*/
public String getPci() {
return pci;
}
/**
* @param author
* the author to set
*/
public void setPci(String pci) {
this.pci = pci;
}
/**
* @return the year
*/
public String getPvs() {
return pvs;
}
/**
* @param year
* the year to set
*/
public void setPvs(String pvs) {
this.pvs = pvs;
}
/**
* @return the country
*/
public String getMassevolumique() {
return massevolumique;
}
/**
* @param country
* the country to set
*/
public void setMassevolumique(String massevolumique) {
this.massevolumique = massevolumique;
}
/**
* @return the language
*/
public String getDensiteair() {
return densiteair;
}
/**
* @param language
* the language to set
*/
public void setDensiteair(String densiteair) {
this.densiteair = densiteair;
}
/**
* @return la masse
*/
public String getMasse() {
return masse;
}
/**
* @param language
* the language to set
*/
public void setMasse(String masse) {
this.masse = masse;
}
public String getFacteurtnt() {
return facteurrtnt;
}
public void setFacteurtnt(String facteurrtnt) {
this.facteurrtnt = facteurrtnt;
}
public String getListe() {
return liste;
}
/**
* @param liste
* the liste to set
*/
public void setListe(String liste) {
this.liste = liste;
}
@Override
public int compareTo(Book book) {
return this.getProduits().compareTo(book.getProduits());
}
} |
la classe Userlistadapter
Code:
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
public class UserListAdapter extends BaseAdapter implements OnClickListener {
private static final String TAG = UserListAdapter.class.getName();
private Activity activity;
public Vector<Book> items;
private Context mContext;
public static CharSequence affichageProduits;
ImageButton retour;
public UserListAdapter(Activity activity, Vector<Book> items) {
Log.i(TAG, TAG);
this.activity = activity;
this.items = items;
}
@SuppressLint("ResourceAsColor")
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
LayoutInflater inflater = activity.getLayoutInflater();
convertView = inflater.inflate(R.layout.listrow_user, null);
holder = new ViewHolder();
holder.name = (TextView) convertView.findViewById(R.id.nameTV);
holder.headingLL = (LinearLayout) convertView
.findViewById(R.id.headingLL);
holder.headingTV = (TextView) convertView
.findViewById(R.id.headingTV);
holder.nameLL = (LinearLayout) convertView
.findViewById(R.id.nameLL);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
if (position < items.size()) {
final Book book = items.get(position);
if (book != null && (book.getProduits().length() == 1)) {
holder.nameLL.setVisibility(View.GONE);
holder.headingLL.setVisibility(View.VISIBLE);
holder.headingTV.setText(book.getProduits());
holder.headingLL
.setBackgroundColor(android.R.color.transparent);
} else {
holder.nameLL.setVisibility(View.VISIBLE);
holder.headingLL.setVisibility(View.GONE);
holder.name.setText(book.getProduits());
View ll = (LinearLayout) holder.name.getParent();
ll.setFocusable(true);
ll.setSelected(true);
ll.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
/* action sur le clic */
if (book.getListe().equals("A") & Intervention.resultatclic==1 ) {
Toast.makeText(activity.getApplicationContext(),
book.getProduits(),
Toast.LENGTH_SHORT).show();
Intent menuIntent = new Intent(activity,Calculbleve.class);
activity.startActivity(menuIntent);
finish();
}
else if (book.getListe().equals("A") & Intervention.resultatclic==2 ){
Toast.makeText(activity.getApplicationContext(),
book.getProduits(),
Toast.LENGTH_SHORT).show();
Intent menuIntent = new Intent(activity,Intervention.class);
activity.startActivity(menuIntent);
finish();
}
if (book.getListe().equals("B") & Intervention.resultatclic==1) {
Toast.makeText(activity.getApplicationContext(),
book.getProduits(),
Toast.LENGTH_SHORT).show(); Ici quand je clic le produits je dois recuperer le nom pour l afficher dans ma troisieme classe
Intent menuIntent = new Intent(activity,Calculbleve.class);
activity.startActivity(menuIntent);
finish();
}
else if (book.getListe().equals("B") & Intervention.resultatclic==2) {
Toast.makeText(activity.getApplicationContext(),
book.getProduits(),
Toast.LENGTH_SHORT).show();
Intent menuIntent = new Intent(activity,Intervention.class);
activity.startActivity(menuIntent);
finish();
}
if (book.getListe().equals("C")) {
Toast.makeText(activity.getApplicationContext(),
book.getProduits(),
Toast.LENGTH_SHORT).show();
}
}
private Context getApplication() {
// TODO Auto-generated method stub
return null;
}
private Context getBaseContext() {
// TODO Auto-generated method stub
return null;
}
private void startActivity(Intent menuIntent) {
// TODO Auto-generated method stub
}
});
}
}
return convertView;
}
protected void finish() {
// TODO Auto-generated method stub
}
private static class ViewHolder {
TextView name, headingTV;
LinearLayout nameLL, headingLL;
}
@Override
public int getCount() {
return items.size();
}
@Override
public Object getItem(int position) {
return items.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
} |
et enfin ma classe calcul ou j ai le probleme
Code:
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
|
public class Calculbleve extends Activity implements OnClickListener{
Button bleve;
ImageButton retour;
TextView titre;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.calculbleve);
LinearLayout monInclude = (LinearLayout) findViewById(R.id.include);
retour = (ImageButton) monInclude.findViewById(R.id.imageButtonRetour);
retour.setOnClickListener(this);// ecoute du bouton sur un clic
titre = (TextView)monInclude.findViewById(R.id.titre);
titre.setText(Book.getProduits()); ici le pb je suis oblige de transformer en static et je ne peux pas sinon ca pose un pb sur mon adapter et affichage.Si je cree une methode complementaire dans Book cela ne m affiche rien.
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (v==retour){
Intent retourIntent = new Intent (this, IndexTableActivityAB.class);
startActivity(retourIntent);
finish();
}
}
} |
Voila les infos sont marquées en rouge dans les class
Le toast est simplement la pour vérifier pendant mon développement le produit cliquer et voir que ca fonctionne et que mon clic démarre bien sur ma nouvelle classe
merci encore pour vos infos et votre aide
cordialement Eric