开发者

Android: How to read a number as int from a String; basically to read Text of a ListViewItem?

开发者 https://www.devze.com 2023-01-19 23:17 出处:网络
This is my problem. I have a ListView, each row is a CheckedTextView. The list view items are\"1\", \"2\" and \"3\".

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 = (开发者_如何学C(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


String aString = "78";
int aInt = Integer.parseInt(aString);
0

精彩评论

暂无评论...
验证码 换一张
取 消