0

This is my problem.

I have a ListView, each row is a CheckedTextView. The list view items are "1", "2" and "3". When a ListItem is clicked, I want to read the number and assign it to an int variable. I did the following to read the Text of the clicked item:

onItemClick(AdapterView<?> parent, View v, int position, long id) {             
  int num = 0; //initialise to 0
  CharSequence s = ((TextView)v).getText();
 // s contains the number, how to get it into num?
}

Basically, I want the number read in s to be converted and given to num. I know it maybe simple, but please help if you have an answer..

Regards, Kiki

kiki
  • 13,627
  • 17
  • 49
  • 62

1 Answers1

1
String aString = "78";
int aInt = Integer.parseInt(aString);
Asahi
  • 13,378
  • 12
  • 67
  • 87
  • Yes I got it from another question in StackOverflow. toString() function converts the CharSequence into String before using this code. So finally, num = Integer.parseInt(((TextView)v).getText().toString()); – kiki Oct 13 '10 at 07:37