【发布时间】:2016-12-21 15:18:54
【问题描述】:
这是我的问题: 首先我有一个这样的列表视图:
当我点击第一行(例如 prod3)时,我的对话框出现如下(这是删除点击的行):
但是当我刷新我的片段时会发生这种情况:
为什么? Android上有类似“重新验证,重新绘制”(java)的功能吗?
这是我点击行时的代码:
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);
编辑:
这是我的自定义适配器
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;
}
}
【问题讨论】:
-
请添加自定义适配器
-
刷新 ListView 时可能在
movieList中添加的项目。只需清除movieList,然后在referh 上添加项目 -
还有你如何在代码中初始化movieList
-
你如何填写你的 moveList ?我认为您正在将对象添加到列表中
-
moveList.clear() ,或者使用本地对象而不是全局 @francescobocci
标签: android listview fragment refresh