0
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
由構造函數傳遞。爲什麼LayoutInflater無法實現小部件的當前值?
當我運行此代碼並按下按鈕時,它始終輸出在XML文件中設置的值。我想這可能與cxt
有關。任何人都可以幫我解決這個問題嗎?
那麼,你是膨脹一個全新的視圖,而不是使用任何可見的用戶/你改變了任何你的其他代碼。你在哪裏設置了「R.id.total_of_price」字段的文本?你是如何在那裏得到對'TextView'的引用的? – ianhanniballake
你說得對。我在一個片段中設置了R.id.total_of_price,在這個片段中構建了一個包含這個字段的視圖。因此,layout.flate.inflate將建立一個新的視圖,而不是返回我之前構建的視圖。 –