본문 바로가기
Android

EditText/TextView/ImageView/Button/Radio/RadioGroup/URI/Intent

by 일용직 코딩노동자 2019. 9. 10.
728x90
반응형

MainActivity.java

import android.content.Intent;
import android.media.Image;
import android.net.Uri;
import android.support.annotation.IdRes;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;


public class MainActivity extends AppCompatActivity
{
EditText edtText = null;
Button button1 = null;
Button button2 = null;
RadioButton radio1 = null;
RadioButton radio2 = null;
ImageView imageView;
RadioGroup radioGroup;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

edtText = findViewById(R.id.edtText);
button1 = findViewById(R.id.button1);
button2 = findViewById(R.id.button2);
radio1 = findViewById(R.id.radio1);
radio2 = findViewById(R.id.radio2);
imageView = findViewById(R.id.imageView);
radioGroup =findViewById(R.id.radioGroup);
radioGroup.setOnCheckedChangeListener(radioGroupButtonChangeListener);


}

public void mOnClick(View v)
{
switch(v.getId())
{
case R.id.button1:
Toast.makeText(getApplicationContext(),edtText.getText().toString(),Toast.LENGTH_SHORT).show();
break;
case R.id.button2:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(edtText.getText().toString()));
startActivity(intent);
// Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("tel:010-1000-1000"));
// startActivity(intent);
break;
}
}

RadioGroup.OnCheckedChangeListener radioGroupButtonChangeListener = new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i) {
if(i == R.id.radio1){

imageView.setImageResource(R.drawable.oreo);

}
else if(i == R.id.radio2){

imageView.setImageResource(R.drawable.pie);
}
}
};
}


activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edtText"
/>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="글자 나타내기"
android:id="@+id/button1"
android:onClick="mOnClick"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="홈페이지 열기"
android:id="@+id/button2"
android:onClick="mOnClick"
/>

<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/radioGroup"

>

<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="오레오"
/>

<RadioButton
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="파이"
/>
</RadioGroup>

<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/oreo"/>
</LinearLayout>

 

--결과--

 

 

궁금하신 사항은 댓글 남겨주세요.

728x90
반응형

'Android' 카테고리의 다른 글

SharedPreferences (간단한 정보저장)  (0) 2019.09.10
비콘감지  (11) 2019.09.10
Image ViewPager  (11) 2019.09.10
ViewPager  (0) 2019.09.10
ListView  (0) 2019.09.10

댓글