это моя проблема: Во-первых у меня есть ListView, как это:Почему, когда я обновляю свой список, он дублирует?
Когда я нажимаю на первом ряду (для expemple prod3) появляется мой подобный диалог (это для удаления щелкнули строки):
Но когда я обновить мой фрагмент происходит эта вещь:
Почему? есть функция типа «revalidate, repaint» (java) на Android?
Это мой код, когда я нажимаю на строке:
public void mostraProdotto(String tito){
final EditText textprod;
final EditText prezzo;
Button btnConf;
Button btnDelete;
final Dialog dialogCustom = new Dialog(getActivity());
dialogBuilder = new AlertDialog.Builder(getActivity());
//process
dialogCustom.setContentView(R.layout.spesa_pagata);
dialogCustom.setTitle("Nome Prod");
textprod = (EditText)dialogCustom.findViewById(R.id.textprod);
textprod.setText(tito);
prezzo = (EditText)dialogCustom.findViewById(R.id.txtprezzo);
btnConf = (Button)dialogCustom.findViewById(R.id.btnConf);
btnConf.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String nomeprod = textprod.getText().toString();
String strprezzo = prezzo.getText().toString();
if(!nomeprod.isEmpty() && !strprezzo.isEmpty()) {
..............
new getSpesa().execute(); //getSpesa is for see listview
dialogCustom.cancel();
}
}
});
и это код для заполнения списка:
listView = (ListView) rootView.findViewById(R.id.list_spesa);
listView.setY(20);
adapter = new CustomListAdapterSpesa(getActivity(), movieList);
adapter.notifyDataSetChanged();
listView.setAdapter(adapter);
EDIT:
это мой customadapter
public class CustomListAdapterSpesa extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
private List<MovieSpesa> movieItems;
int pos;
public CustomListAdapterSpesa(Activity activity, List<MovieSpesa> movieItems) {
this.activity = activity;
this.movieItems = movieItems;
}
@Override
public int getCount() {
return movieItems.size();
}
@Override
public Object getItem(int location) {
return movieItems.get(location);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (inflater == null)
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.list_row, null);
TextView title = (TextView) convertView.findViewById(R.id.title);
TextView genre = (TextView) convertView.findViewById(R.id.genre);
convertView.findViewById(R.id.releaseYear);
MovieSpesa m = movieItems.get(position);
int coint = getCount();
// title
title.setText(m.getTitle());
// genre
genre.setText(m.getGenre());
return convertView;
}
}
Пожалуйста, добавьте пользовательский адаптер –
Вероятно, элементы, добавленные в 'movieList' при обновлении ListView. просто очистите 'movieList' перед добавлением элементов на referh –
А также как вы инициализируете movieList в коде –