我正在从 sqlite 数据库中检索提供优惠的国家/地区列表。
我想在应按国家/地区显示的 ListView 中显示这些优惠。例如:假设印度有 5 个报价,那么它应该显示:印度,然后是所有 5 个报价;然后是其他国家和他们的报价等等..
数据应以复选框显示。如果未选中该复选框,则应突出显示该项目。代码如下
_arrayAdapterActiveCards = new ArrayAdapter<Card>(this, R.layout.active_card_list_item, _activeUserCards)
{
LayoutInflater layout_inflater = LayoutInflater.from(getApplicationContext());
@Override
public Card getItem(int position)
{
return _activeUserCards.get(position);
}
@Override
public long getItemId(int position)
{
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
Card select_card = getItem(position);
if (convertView == null)
{
convertView = layout_inflater.inflate(R.layout.active_card_list_item, null);
}
String selected_card = select_card.getBankName() + " - " + select_card.getCardName().replaceAll("\\s+$", "");
final ViewHolder holder = new ViewHolder();
holder.card_name_view = (TextView) convertView.findViewById(R.id.active_card_name_view);
holder.card_name_view.setText(selected_card);
holder._checkBox = (CheckBox) convertView.findViewById(R.id.active_card_checkbox);
holder._checkBox // here implement check box facility
.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
String savedItems = null;
if (!_listViewForActiveCards.isItemChecked(position))
{
Log.d(TAG, "Value of position = " + position);
}
_arrayAdapterActiveCards.notifyDataSetChanged();
}
});
return convertView;
}
class ViewHolder
{
TextView card_name_view;
CheckBox _checkBox;
}
};
_arrayAdapterActiveCards.setNotifyOnChange(true);
_listViewForActiveCards.setAdapter(_arrayAdapterActiveCards);
for (int i = 0; i < _noOfCountry; i++)
{
final LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
_fragmentLayoutActiveCard = (LinearLayout) inflater.inflate(R.layout.fragment_layout, null);
_fragmentLayoutActiveCard.setId(i);
_lLayout = (LinearLayout) findViewById(R.id.countryAndCardListLayout);
_countryText[i] = new TextView(this);
_countryText[i].setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
_countryText[i].setText(_countryName[i].toUpperCase());
_countryText[i].setTextColor(Color.BLACK);
_lLayout.addView(_countryText[i]);
_lLayout.addView(_fragmentLayoutActiveCard);
_listViewForActiveCards = (ListView) findViewById(R.id.fragmentCardList);
getCardFromDataBaseTestMethodActiveCard(_countryName[i]);
}