我有一个使用自定义ListAdapter构建的listView。我需要访问列表视图中的所有子项,以便在ListView的每个项中获取TextView的所有文本。
private void calcTotalSales ()
{
View v;
TextView tx;
String abc="";
ListView myList = (ListView) findViewById(R.id.todaySalesListView);
for (int i = 0; i < myList.getChildCount(); i++)
{
v = (View) myList.getChildAt(i);
tx = (TextView) v.findViewById(R.id.quantityTB);
Log.d ("Text", tx.getText().toString());
}
}
我的listAdapter中的一部分:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
final int _position = position;
if (convertView == null) {
convertView = l_Inflater.inflate(R.layout.activity_today_sales_list_view, null);
holder = new ViewHolder();
holder.txt_itemName = (TextView) convertView.findViewById(R.id.itemNameTB);
holder.txt_itemPrice = (TextView) convertView.findViewById(R.id.priceTB);
holder.txt_itemQuantity = (TextView) convertView.findViewById(R.id.quantityTB);
holder.txt_plusBtn = (Button) convertView.findViewById(R.id.addBtn);
holder.txt_minusBtn = (Button) convertView.findViewById(R.id.minusBtn);
holder.txt_plusBtn.setTag(holder);
holder.txt_minusBtn.setTag(holder);
convertView.setTag(holder);
holder.txt_plusBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Set Text of TextView
}
});
holder.txt_minusBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Set Text of TextView
}
});
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txt_itemName.setText(itemDetailsrrayList.get(position).getItemName());
holder.txt_itemPrice.setText("RM "+itemDetailsrrayList.get(position).getItemCost());
return convertView;
}
以下是我面临的问题:
任何人都可以提供帮助吗?