Click here to Skip to main content
15,910,471 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am trying to get a substring of a string to be displayed from an editText to a textView. i used addTextChangedListener to the edittext to perform this operation

in this method i am trying to get a substring from the edittext to be shown in the textView on running the app nothing happens.

Java
public void afterTextChanged(Editable s) {
			// TODO Auto-generated method stub
			TextView gtin = (TextView) findViewById(R.id.textView2);
			String sgtin=gtin.getText().toString();
			sgtin.substring(0,7);
			   gtin.setText(sgtin);
		}


where have i possible gone wrong. need guidence
Posted

1 solution

Java's substring() returns a string : http://www.tutorialspoint.com/java/java_string_substring.htm[^]
so you should :
Java
String str = sgtin.substring(0,7);
gtin.setText(str);
 
Share this answer
 
Comments
Rahul Ramakrishnan 6-Jun-15 1:02am    
i am getting lots of errors

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900