-
안드로이드 평번한 예제1과거...../개발일지 2010. 6. 2. 12:35
1. 텍스트 박스에서 입력하는 순서대로 같은 화면안에 리스트뷰에 뿌리는 예제
2. 버튼누를때마다 이미지뷰에 그림이 바뀜(drawable내에있는 그림들)
package com.homework;
import java.util.ArrayList;
import com.homework.R.drawable;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;public class MainActivity extends Activity {
Button B_Input,B_ImageView;
EditText E_Input;
ImageView m_ImageView;
ListView Input_List;
int count=0;
ArrayList list = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
B_Input = (Button)findViewById(R.id.B_Input);
B_ImageView = (Button)findViewById(R.id.B_ImageView);
E_Input = (EditText)findViewById(R.id.E_Input);
m_ImageView = (ImageView)findViewById(R.id.m_ImageView);
Input_List = (ListView)findViewById(R.id.Input_List);
list = new ArrayList();
final ArrayAdapter aa = new ArrayAdapter(this,R.layout.row,list);
Input_List.setAdapter(aa);
B_Input.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
list.add(E_Input.getText().toString());
aa.notifyDataSetChanged();
}
});
B_ImageView.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
int[] image_drawable = {R.drawable.a1,R.drawable.a2,R.drawable.a3};
if (count==3) count=0;
m_ImageView.setImageResource(image_drawable[count]);
count++;
}
});
}
}