Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.sam.scrollviewprac;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.LinearLayout;
- import android.widget.ScrollView;
- import android.widget.TextView;
- public class MainActivity extends AppCompatActivity {
- private TextView tvCount;
- private ScrollView scrollView;
- private LinearLayout linearLayout;
- private int count = 0;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- findViews();
- // Counter default value: 0
- this.tvCount.setText(Integer.toString(this.count));
- }
- private void findViews() {
- tvCount = (TextView)findViewById(R.id.tvCount);
- scrollView = (ScrollView)findViewById(R.id.scrollView);
- linearLayout = (LinearLayout)findViewById(R.id.linearLayout);
- }
- public void onAddClick(View view){
- this.count++;
- this.tvCount.setText(Integer.toString(this.count));
- TextView textView = new TextView(this);
- textView.setText(Integer.toString(this.count) + ": This is a line.");
- this.linearLayout.addView(textView);
- // first updated and then scrolls to the "new" bottom
- scrollView.postDelayed(new Runnable(){
- @Override
- public void run() {
- scrollView.fullScroll(View.FOCUS_DOWN);
- }
- }, 100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement