简体   繁体   中英

How to display ListView Selected item with ViewPager in android

I want to move the selected quotes (text) from the ListView and display that selected item in another activity with ViewPager + Next and Previous button that show the next and previous element inside the ListView... (Thanks in advance...) Here is my Code...

lvAmazingQuotes.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                String selectedQuote = amazing_Quotes_List.get(position);
                Toast.makeText(AmazingQuotes_Activity.this, selectedQuote, Toast.LENGTH_SHORT).show();
            }
        });

ScreenShot:

Using this code you can send your selected item, previous item and next item to another activity

lvAmazingQuotes.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String previousitem= amazing_Quotes_List.get(position-1).toString();   
            String selectedQuote = amazing_Quotes_List.get(position).toString();
             String nextitem= amazing_Quotes_List.get(position+1).toString();

            Intent intent = new Intent(context, AnotherActivity.class);
              intent.putExtra("previous_item", previousitem);
               intent.putExtra("selected_quote", selectedQuote);
               intent.putExtra("next_item", nextitem);
             context.startActivity(intent);
        }
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM