Note that there are some explanatory texts on larger screens.

plurals
  1. POOnRestart Activity, bad item is highlighted in a listview
    primarykey
    data
    text
    <p>My listview is created with a relativeLayout. When I touch the "texViewLibelleListe", the item of the listview is highlighted (in "bleu_c") with the OnClick method and start a new activity ("ActiviteSoldeAchat"). When I destroy this activity ("ActiviteSoldeAchat"), the first activity restart.</p> <p>My question : I want to disable the highlight of a all item in the listview when I restart the activity or highlight the good item. How can I do this? At this time, this is not the good item that is highlighted. Any idea?</p> <p>Thank you for your help</p> <p>The only one solution I found is to reload entirely the listview in the OnResume method like this : adapter = new ListeAdapter(this, listeRepository.GetAll()); ListListe.setAdapter(adapter);</p> <h2>But I think, it's not a clean solution</h2> <p>The main activity :</p> <pre><code>public class ActiviteSoldeListe extends Activity { ListView ListListe; Button boutonAjouterListe; private ListeAdapter adapter; private ListeRepository listeRepository=new ListeRepository(this);; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.soldeliste); //On récupère tous les éléments de notre interface graphique grâce aux ID ListListe = (ListView) findViewById(R.id.listListe); // ouverture de la base listeRepository.Open(); // récupération de tous les éléments de la table achat et adaptateur adapter = new ListeAdapter(this, listeRepository.GetAll()); // fermeture de la base listeRepository.Close(); ListListe.setAdapter(adapter); } //au lancement de l'activité protected void onStart(){ super.onStart(); } protected void onRestart(){ super.onRestart(); } protected void onResume(){ super.onResume(); UpdateAdapter(); } private void UpdateAdapter() { listeRepository.Open(); adapter.setListes(listeRepository.GetAll()); listeRepository.Close(); adapter.notifyDataSetChanged(); } </code></pre> <p>Tha adpater for the listview :</p> <pre><code>public class ListeAdapter extends BaseAdapter implements OnClickListener{ private List&lt;Liste&gt; listeListe; private LayoutInflater inflater; private Context context; public int confirmDelete; public void setListes(List&lt;Liste&gt; listeListe) { this.listeListe = listeListe; } public ListeAdapter(Context context, List&lt;Liste&gt; listeListe) { this.listeListe = listeListe; this.setContext(context); this.inflater = LayoutInflater.from(context); } public int getCount() { return listeListe.size(); } public Object getItem(int position) { return listeListe.get(position); } public long getItemId(int position) { return listeListe.get(position).getId(); } private class ViewHolder { public TextView tvLibelleListe; public TextView tvDate; public Button btSupprimer; } public View getView(final int position, View view, ViewGroup viewGroup) { final ViewHolder holder; if (view == null) { holder = new ViewHolder(); view = inflater.inflate(R.layout.layout_item_liste, null); holder.tvLibelleListe = (TextView) view .findViewById(R.id.textViewLibelleListe); holder.tvDate = (TextView) view .findViewById(R.id.textViewDate); holder.btSupprimer = (Button) view .findViewById(R.id.buttonSupprimerListe); view.setTag(holder); } else { holder = (ViewHolder) view.getTag(); } final Integer IdListe = listeListe.get(position).getId(); final RelativeLayout listlayout = (RelativeLayout) view.findViewById(R.id.ListViewListe); holder.tvLibelleListe.setText(listeListe.get(position).getLibelleListe() + " - " + listeListe.get(position).getouvert()); holder.tvDate.setText(listeListe.get(position).getdate() + ""); holder.btSupprimer.setOnClickListener(new OnClickListener() { public void onClick(View v) { ConfirmDelete(getContext(), IdListe); } }); holder.tvLibelleListe.setOnClickListener(new OnClickListener() { public void onClick(View v) { listlayout.setBackgroundResource(R.color.bleu_f); ActiviteSoldeListe soldeListeActivity = (ActiviteSoldeListe) getContext(); Intent intent = new Intent(); intent.setClass(soldeListeActivity, ActiviteSoldeAchat.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra("IdListe",IdListe); soldeListeActivity.startActivity(intent); } }); holder.tvDate.setOnClickListener(new OnClickListener() { public void onClick(View v) { listlayout.setBackgroundResource(R.color.bleu_f); ActiviteSoldeListe soldeListeActivity = (ActiviteSoldeListe) getContext(); Intent intent = new Intent(); intent.setClass(soldeListeActivity, ActiviteSoldeAchat.class); intent.putExtra("IdListe",IdListe); soldeListeActivity.startActivity(intent); } }); return view; } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload