我看到link,但没有答案。
有人能解释为什么会发生这件事吗? 这个事件如何触发? 如何解决?
在观察我的listview后,我的LayoutInflater是添加我的多个页眉和页脚的原因..我怎么能阻止它添加项目或重置我的LayoutInflater?
这是我的代码在onResume触发时从ListView填充项目
public void fillListViewOR(List<HashMap<String, String>> list)
{
String[] from = {
"textViewModeOfPaymentCheckValue",
"textViewBankNameCheckIssued",
"textViewCheckNumber",
"textViewCheckDateValue",
"textViewModeOfPayCheckValue"};
int[] to = { R.id.textViewModeOfPaymentCheckValue,
R.id.textViewBankNameCheckIssued,
R.id.textViewCheckNumValue,
R.id.textViewCheckDateValue,
R.id.textViewModeOfPayCheckValue};
String[] from2 = {
"textViewModeOfPaymentCheckValue",
"textViewBankNameCheckIssued",
"textViewCheckNumber",
"textViewCheckDate",
"textViewModeOfPayCheckValue"};
int[] to2 = { R.id.textViewModeOfPaymentCheckValue,
R.id.textViewBankNameCheckIssued,
R.id.textViewCheckNumber,
R.id.textViewCheckDate,
R.id.textViewModeOfPayCheckValue};
adapterListView = new SpecialAdapter(getBaseContext(),list,R.layout.listview_layout,from2,to2);
adapterListView.notifyDataSetChanged();
headerViewOR = ((LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.jpos_or_header, null, false);
//bodyView = ((LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.listview_layout, null, false);
footerViewOR = ((LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.jpos_or_footer, null, false);
lv.addHeaderView(headerViewOR);
lv.addFooterView(footerViewOR);
lv.setAdapter(adapterListView);
----------------------
--- and so on from the view items of the header and footer
}
这是我的特殊适配器
public class SpecialAdapter extends SimpleAdapter {
public static TextView tv;
private int[] colors = new int[] { 0xffcccccc , 0xffffffff };
private int[] colors2 = new int[] { 0xffffffff , 0xff000000 };
// Context context;
public SpecialAdapter(Context context, List<HashMap<String, String>> items, int resource, String[] from, int[] to) {
super(context, items, resource, from, to);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
int colorPos = position % colors.length;
view.setBackgroundColor(colors[colorPos]);
//TextView textView = (TextView)view.findViewById(R.id.textViewModAmountCheck);
//textView.setText("AlvinTest");
return view;
}
public View getView2(Context context, int position, View convertView, ViewGroup parent) {
LayoutInflater layoutInflater = LayoutInflater.from(context);//get your layout inflator;
//LayoutInflater inf = LayoutInflater.from(getContext());
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.listview_layout, null);
}
LinearLayout yyy = (LinearLayout) convertView.findViewById(R.id.linearCheckDate);
yyy.setVisibility(View.GONE);
return convertView;
}
public View getViewChild(Context context, int position, View convertView, ViewGroup parent) {
LayoutInflater layoutInflater = LayoutInflater.from(context);//get your layout inflator;
// LayoutInflater inf = LayoutInflater.from(this);
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.listview_layout, null);
}
LinearLayout yyy = (LinearLayout) convertView.findViewById(R.id.linearCheckDate);
yyy.setVisibility(View.GONE);
return convertView;
}
public boolean setViewValue(View view, Cursor cursor, int columnIndex){
int getIndex = cursor.getColumnIndex("Name");
String empname = cursor.getString(getIndex);
tv = (TextView) view;
tv.setTextColor(Color.WHITE);
tv.setText(empname);
if(empname.equals("Any String"))
{
tv.setTextColor(Color.rgb(58, 58, 224));
return true;
}
return false;
}
}
答案 0 :(得分:0)
我会尝试评论这一行:
adapterListView.notifyDataSetChanged();
我认为这会导致您的数据被处理两次。
答案 1 :(得分:0)
使用LayoutInflater代码的所有ListView操作必须放在@onCreate
而不是@onResume
这是我的错误,因为我使用了错误的填充ListView的格式,因为我使用了我的这个过程我的申请的先前操作。
因为当我们关闭应用程序时,它会保留布局,并在我们重新打开应用程序后转到
@onResume
,@onStart
,它不会转到@onCreate
操作,因为它是已创建。这就是为什么我的列表视图有多个页眉和页脚视图的原因。