我的列表视图是使用 relativeLayout 创建的。当我触摸“texViewLibelleListe”时,使用 OnClick 方法突出显示列表视图的项目(在“bleu_c”中)并开始一个新活动(“ActiviteSoldeAchat”)。当我销毁此活动(“ActiviteSoldeAchat”)时,第一个活动重新启动。
我的问题:当我重新启动活动或突出显示好项目时,我想禁用列表视图中所有项目的突出显示。我怎样才能做到这一点?此时,这不是突出显示的好项目。任何想法?
谢谢您的帮助
我发现的唯一一种解决方案是在 OnResume 方法中完全重新加载列表视图,如下所示: adapter = new ListeAdapter(this, listeRepository.GetAll()); ListListe.setAdapter(适配器);
但我认为,这不是一个干净的解决方案
主要活动:
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();
}
列表视图的 Tha adpater :
public class ListeAdapter extends BaseAdapter implements OnClickListener{
private List<Liste> listeListe;
private LayoutInflater inflater;
private Context context;
public int confirmDelete;
public void setListes(List<Liste> listeListe) {
this.listeListe = listeListe;
}
public ListeAdapter(Context context, List<Liste> 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;
}
}