package com.example.administrator.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements Runnable
{
ProgressBar bar1;
ProgressBar bar2;
ProgressBar bar3;
EditText txt1;
EditText txt2;
EditText txt3;
Button btn1;
Button btn2;
Button btn3;
int progress1=0;
int progress2=0;
int progress3=0;
Thread thread;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bar1 = (ProgressBar)findViewById(R.id.bar1);
txt1 = (EditText)findViewById(R.id.txt1);
btn1 = (Button)findViewById(R.id.btn1);
bar2 = (ProgressBar)findViewById(R.id.bar2);
txt2 = (EditText)findViewById(R.id.txt2);
btn2 = (Button)findViewById(R.id.btn2);
bar3 = (ProgressBar)findViewById(R.id.bar3);
txt3 = (EditText)findViewById(R.id.txt3);
btn3 = (Button)findViewById(R.id.btn3);
btn1.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{
Toast.makeText(getApplicationContext(), "1번 버튼", Toast.LENGTH_SHORT).show();
}
});
btn2.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{
Toast.makeText(getApplicationContext(), "2번 버튼", Toast.LENGTH_SHORT).show();
}
});
btn3.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{
Toast.makeText(getApplicationContext(), "3번 버튼", Toast.LENGTH_SHORT).show();
}
});
txt1.addTextChangedListener(new TextWatcher()
{
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
//TODO Auto-generated method stub
try
{
progress1 = Integer.parseInt(txt1.getText().toString());
bar1.setProgress(progress1);
}
catch (Exception e){}
}
@Override
public void afterTextChanged(Editable s){}
});
txt2.addTextChangedListener(new TextWatcher()
{
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
//TODO Auto-generated method stub
try
{
progress2 = Integer.parseInt(txt2.getText().toString());
bar2.setProgress(progress2);
}
catch (Exception e){}
}
@Override
public void afterTextChanged(Editable s){}
});
txt3.addTextChangedListener(new TextWatcher()
{
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
//TODO Auto-generated method stub
try
{
progress3 = Integer.parseInt(txt3.getText().toString());
bar3.setProgress(progress3);
}
catch (Exception e){}
}
@Override
public void afterTextChanged(Editable s){}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
public void Start(View v)
{
thread = new Thread(this);
thread.start();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void run()
{
progress1=0;
while(progress1 < 100)
{
++progress1;
bar1.setProgress(progress1);
try
{
thread.sleep(1000);
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}