public void onClick(View v) {
AdapterFood.get(position).setNumber_of_order(AdapterFood.get(position).getNumber_of_order()+1);
LayoutInflater layoutInflater=(LayoutInflater)cxt.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View total=layoutInflater.inflate(fragment_shopping_cart,null);
TextView totaltxt=(TextView)total.findViewById(R.id.total_of_price);
System.out.println(totaltxt.getText().toString());
notifyDataSetChanged();
}
它是ListView
适配器的代码的一部分,此点击侦听器位于getView
的方法中。 cxt
由构造函数传递。
当我运行此代码并按下按钮时,它始终输出在XML文件中设置的值。我想这可能与cxt
有关。谁能帮我拍这个问题?
答案 0 :(得分:0)
试试这个:
LayoutInflater layoutInflater = getLayoutInflater(null);
View total=layoutInflater.inflate(fragment_shopping_cart, parent, false);
答案 1 :(得分:0)
我在一个片段中设置了R.id.total_of_price,我构建了一个包含该字段的视图。因此layoutinflate.inflate将构建一个新视图,而不是返回我之前构建的视图。