0

我正在从 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]);
}
4

2 回答 2

0

我就是这样理解你的问题的。一个一个地显示每个国家和他们的报价(通过数据库检索的信息)。为此,您可能必须实现自定义数组适配器并相应地显示它。

于 2012-09-24T06:15:49.797 回答
0

Try this: http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android-09/

** Please provide code in proper format. It will help you to get your answer correctly and quickly.

于 2012-09-24T05:21:25.577 回答