Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8974773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:44:40+00:00 2026-06-15T18:44:40+00:00

I’ve read the previous threads on stackoverflow how to extract the text from a

  • 0

I’ve read the previous threads on stackoverflow how to extract the text from a current selected list item. I used the getSelectedItem method but that doesn’t work. What I want to do is get the text from the list element and then on a swipe gesture pass this text onto the other activity. Here is my code for the swipe gesture.

public class Descriptor extends ListActivity {

private GestureDetector gestureDetector;
@SuppressWarnings("deprecation")

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

    setContentView(R.layout.descriptor);

    gestureDetector = new GestureDetector(new SwipeGestureDetector());

    ListView listView = (ListView) findViewById(android.R.id.list);
     // storing string resources into Array
   String[] story_titles = getResources().getStringArray(R.array.story_list);

   // Binding resources Array to ListAdapter

   ArrayAdapter<String> adapter = new ArrayAdapter<String> (this,android.R.layout.simple_list_item_1,android.R.id.text1,story_titles);

   listView.setAdapter(adapter);

   //set single choice of list at a time
   listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);


   //setting the story description when item clicked from selector class

   TextView story_desc = (TextView) findViewById(R.id.story_desc);

   ImageView image_desc = (ImageView) findViewById(R.id.imageView1);


   Intent i = getIntent();

   String title = i.getStringExtra("title");

   if(title.equalsIgnoreCase("The Ant and the Grasshopper")){
   story_desc.setText(R.string.ant_desc);
   image_desc.setImageResource(R.raw.ant_and_grasshopper);
   }

   if(title.equalsIgnoreCase("The Fox and the Grapes")) {
       story_desc.setText(R.string.fox_desc);
       image_desc.setImageResource(R.raw.fox);
   }

   if(title.equalsIgnoreCase("The Wind and the Sun")){
       story_desc.setText(R.string.wind_desc);
       image_desc.setImageResource(R.raw.wind_and_the_sun);
   }

   if(title.equalsIgnoreCase("The Miser and his Gold")){   
       story_desc.setText(R.string.miser_desc);
       image_desc.setImageResource(R.raw.miser);
   }

   if(title.equalsIgnoreCase("The Frog and the Ox")){
       story_desc.setText(R.string.frog_desc);
       image_desc.setImageResource(R.raw.frog_and_ox);
   }

}

public void onListItemClick(ListView parent,View view, int position, long id) {
    String title = ((TextView) view).getText().toString();

    TextView story_desc = (TextView) findViewById(R.id.story_desc);

    ImageView image_desc = (ImageView) findViewById(R.id.imageView1);

    if(title.equalsIgnoreCase("The Ant and the Grasshopper")){
           story_desc.setText(R.string.ant_desc);
           image_desc.setImageResource(R.raw.ant_and_grasshopper);
           }

           if(title.equalsIgnoreCase("The Fox and the Grapes")) {
               story_desc.setText(R.string.fox_desc);
               image_desc.setImageResource(R.raw.fox);
           }

           if(title.equalsIgnoreCase("The Wind and the Sun")){
               story_desc.setText(R.string.wind_desc);
               image_desc.setImageResource(R.raw.wind_and_the_sun);
           }

           if(title.equalsIgnoreCase("The Miser and his Gold")){   
               story_desc.setText(R.string.miser_desc);
               image_desc.setImageResource(R.raw.miser);
           }

           if(title.equalsIgnoreCase("The Frog and the Ox")){
               story_desc.setText(R.string.frog_desc);
               image_desc.setImageResource(R.raw.frog_and_ox);
           }


}

public boolean onTouchEvent(MotionEvent event) {
    if (gestureDetector.onTouchEvent(event)) {
      return true;
    }
    return super.onTouchEvent(event);
  }

private void onLeftSwipe() {


   Intent intent = new Intent(this,Story.class);
   startActivity(intent);
  }

  private void onRightSwipe() {
    // Do something
  }


private class SwipeGestureDetector extends SimpleOnGestureListener {

    private static final int SWIPE_MIN_DISTANCE = 120;
    private static final int SWIPE_MAX_OFF_PATH = 200;
    private static final int SWIPE_THRESHOLD_VELOCITY = 200;

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2,
         float velocityX, float velocityY) {
      try {
        float diffAbs = Math.abs(e1.getY() - e2.getY());
        float diff = e1.getX() - e2.getX();

        if (diffAbs > SWIPE_MAX_OFF_PATH)
          return false;

        // Left swipe
        if (diff > SWIPE_MIN_DISTANCE
        && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
           Descriptor.this.onLeftSwipe();

        // Right swipe
        } else if (-diff > SWIPE_MIN_DISTANCE
        && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
          Descriptor.this.onRightSwipe();
        }
      } catch (Exception e) {
        Log.e("YourActivity", "Error on gestures");
      }
      return false;
    }
    } 
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

}

Please note that my gesture works fine if i omit the listview and string objects but gives an exception if I do this. Any suggestions ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:44:41+00:00Added an answer on June 15, 2026 at 6:44 pm

    Have a look here for what getSelectedItem() does. Unless your list has a selection method (check this for a beautiful answer on how to achieve this), you can’t use it. Now if you want to do the above when swiping left on a particular row, then you should an OnTouchListener on each row view (to capture the left swipe) and then, as suggested before, use setTag() and getTag() in that same view in order to store and retrieve the string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.