«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

ITGenerations

안드로이드 앱 만들기1 본문

Univ/안드로이드

안드로이드 앱 만들기1

ITGenerations 2018. 4. 19. 22:33

1.  글자 나타내기를 클릭하면  입력한 글자가 잠깐 메세지로 출력

2. 홈페이지 열기를 클릭하면 입력한 URL이 열림

3. 처음에는 기본 이미지만 나타나고, 라디오 버튼을 클릭하면 다른 이미지로 변경



Java source

package com.example.ryan.study;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
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 editText;
Button btn1, btn2;
RadioGroup rdg;
RadioButton rdbtn1, rdbtn2;
ImageView image1,image2;

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

editText = (EditText) findViewById(R.id.edit);
btn1 = (Button) findViewById(R.id.btn1);
btn2 = (Button) findViewById(R.id.btn2);
rdg = (RadioGroup) findViewById(R.id.radg);
rdbtn1 = (RadioButton) findViewById(R.id.rdbtn1);
rdbtn2 = (RadioButton) findViewById(R.id.rdbtn2);
image1 = (ImageView) findViewById(R.id.image1);
image2 = (ImageView) findViewById(R.id.image2);


// editText.setText(new View.);

editText.getText();
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

//Log.v("글자나타내기",editText.getText().toString());
//Toast.makeText(getApplicationContext(),editText.getText().toString(),Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "글자 나타내기", Toast.LENGTH_SHORT).show();
}
});

btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "http://m.doum.net", Toast.LENGTH_SHORT).show();
Intent mIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(editText.getText().toString()));
startActivity(mIntent);
}
});


rdg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
if(rdbtn1.isChecked()==true){
image1.setVisibility(View.VISIBLE);
image2.setVisibility(View.INVISIBLE);
}
else if(rdbtn2.isChecked()==true){
image1.setVisibility(View.INVISIBLE);
image2.setVisibility(View.VISIBLE);
}
}
});




}
}



xml source


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

<EditText
android:id="@+id/edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="http://m.daum.net" />

<Button
android:id="@+id/btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="글자 나타내기" />

<Button
android:id="@+id/btn2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="홈페이지 열기" />

<RadioGroup
android:id="@+id/radg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checkedButton="@+id/rdbtn1">

<RadioButton
android:id="@+id/rdbtn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="160dp"
android:text="누가" />

<RadioButton
android:id="@+id/rdbtn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="160dp"
android:text="오레오" />


</RadioGroup>

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible">

<ImageView
android:id="@+id/image1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
app:srcCompat="@drawable/cat1" />

<ImageView
android:id="@+id/image2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible"
app:srcCompat="@drawable/cat2" />
</FrameLayout>


</LinearLayout>