aysen
aysen

Reputation: 49

Show letter-preview when scrolling list

Lista has been made with data collected through an array of my database there. I want to Show letter-preview when scrolling A-Ö list. how can i do it? thanks...

public class L extends BaseActivity {

    private ListView m_listView;
    private DBManager m_db;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.letters);
        customizeTitleBar("A-Ö", null);
        setVisibilityToButton(R.id.left_button, visibilityGone);
        setVisibilityToButton(R.id.right_button, visibilityGone);

        m_db = new DBManager(getApplicationContext());
        m_db.openDataBase();

        m_listView = (ListView)findViewById(R.id.letters_listview);
        m_listView.setFastScrollEnabled(true);

        final ArrayList<Image> words = m_db.selectAllWords();

        WordListAdapter adapter = new WordListAdapter(getApplicationContext(), words);

        m_listView.setAdapter(adapter);

        m_listView.setOnItemClickListener(new OnItemClickListener(){

            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                Intent intent = new Intent(getApplicationContext(), ShowImage.class);

                intent.putExtra("selectedItem", words.get(arg2).getRowId());
                intent.putExtra("word", words.get(arg2).getWord());

                startActivity(intent);
            }
        });
        m_db.closeDatabase();
    }
}

and adapter is:

public class Adapter extends BaseAdapter {


    private LayoutInflater m_inflater;
    private ArrayList<Image> m_data = new ArrayList<Image>();
    ImageHelper m_helper = new ImageHelper();

    public Adapter(Context context, ArrayList<Image> data){
        this.m_inflater = LayoutInflater.from(context);
        this.m_data= data;
    }

    public int getCount() {
        return this.m_data.size();
    }

    public Image getItem(int position) throws IndexOutOfBoundsException{
        return this.m_data.get(position);
    }

    public long getItemId(int position) throws IndexOutOfBoundsException{
        if(position < getCount() && position >= 0 ){
            return position;
        }
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent){

        if(convertView == null){
            convertView = this.m_inflater.inflate(R.layout.lettersrows, null);
        }

        TextView tv = (TextView)convertView.findViewById(R.id.label);

        tv.setText(this.m_data.get(position).getWord());
        tv.setTextSize(25);  

        convertView.setBackgroundColor((position & 1) == 1 ? Color.WHITE : Color.LTGRAY);

        return convertView;
    }
}

Upvotes: 2

Views: 2017

Answers (2)

DonSimonBolivar
DonSimonBolivar

Reputation: 95

I know it's been a while since you asked, but you have to make your Adapter implement SectionIndexer to show the letter while you're fast scrolling. Here's a good example you can look at to see what needs to be done.

http://twistbyte.com/tutorial/android-listview-with-fast-scroll-and-section-index

Upvotes: 2

reflog
reflog

Reputation: 7645

You probably want to set 'setFastScrollEnabled(boolean)' on the ListView.

Upvotes: 0

Related Questions