tv = (TextView)this.findViewById(R.id.tv);
et = (EditText)this.findViewById(R.id.et);
tv.setText(" 1");
et.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(s.length()!=0){
String str = "";
for(int i = 0 ; i<et.getLineCount()+1 ; i++){
str = str + " "+(i+1)+"\n";
}
tv.setText(str);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
layout布局:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<TextView
android:id="@+id/tv"
android:layout_width="50px"
android:layout_height="wrap_content"
android:textSize="12sp"
android:layout_marginTop="20px"
android:gravity="center|right"
android:lineSpacingExtra="2sp"
/>
<EditText
android:id="@+id/et"
android:layout_width="400px"
android:layout_height="wrap_content"
android:textSize="12sp"
android:layout_marginTop="20px"
android:layout_marginLeft="10px"
android:gravity="center|left"
android:lineSpacingExtra="2sp"
/>
</LinearLayout>
![](http://imgsrc.baidu.com/forum/w%3D580/sign=dadd60ef512c11dfded1bf2b53276255/79af0cd7912397dd19403f085f82b2b7d0a2871c.jpg)
et = (EditText)this.findViewById(R.id.et);
tv.setText(" 1");
et.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(s.length()!=0){
String str = "";
for(int i = 0 ; i<et.getLineCount()+1 ; i++){
str = str + " "+(i+1)+"\n";
}
tv.setText(str);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
layout布局:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<TextView
android:id="@+id/tv"
android:layout_width="50px"
android:layout_height="wrap_content"
android:textSize="12sp"
android:layout_marginTop="20px"
android:gravity="center|right"
android:lineSpacingExtra="2sp"
/>
<EditText
android:id="@+id/et"
android:layout_width="400px"
android:layout_height="wrap_content"
android:textSize="12sp"
android:layout_marginTop="20px"
android:layout_marginLeft="10px"
android:gravity="center|left"
android:lineSpacingExtra="2sp"
/>
</LinearLayout>
![](http://imgsrc.baidu.com/forum/w%3D580/sign=dadd60ef512c11dfded1bf2b53276255/79af0cd7912397dd19403f085f82b2b7d0a2871c.jpg)