안드로이드 초보입니다. 제발 알려주세요
늘봄
안드로이드 완전 초보입니다. 하나라도 아시는 분은 부탁드려요! 제발!!
1. 소스 분석 좀 부탁드려요.
package corea.com.preference1;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.EditText;
public class Preference1Activity extends Activity {
EditText edit;
CheckBox check1, check2;
SharedPreferences pref;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
pref = getSharedPreferences(pref, Activity.MODE_PRIVATE);
edit = (EditText)findViewById(R.id.edit);
check1 = (CheckBox)findViewById(R.id.check1);
check2 = (CheckBox)findViewById(R.id.check2);
String text = pref.getString(editText,);
Boolean chk1 = pref.getBoolean(check1, false);
Boolean chk2 = pref.getBoolean(check2, false);
edit.setText(text);
check1.setChecked(chk1);
check2.setChecked(chk2);}
public void onPause(){
super.onPause();
pref = getSharedPreferences(pref, Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = pref.edit();
edit = (EditText)findViewById(R.id.edit);
check1 = (CheckBox)findViewById(R.id.check1);
check2 = (CheckBox)findViewById(R.id.check2);
editor.putString(editText, edit.getText().toString());
editor.putBoolean(check1, check1.isChecked());
editor.putBoolean(check2, check2.isChecked());
editor.commit();
}}
2. getItem(), getItemId()함수를 제거하면 어떤 현상이 발생하는것과 이유.
package corea.com.sss;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
public class SssActivity extends Activity {
/** Called when the activity is first created. */
Integer[] images = {
R.drawable.icon1, R.drawable.icon2, R.drawable.icon3, R.drawable.icon4,
R.drawable.icon5, R.drawable.icon6, R.drawable.icon7
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Gallery gallery = (Gallery) findViewById(R.id.gallery1);
gallery.setAdapter(new ImageAdapter(this));
gallery.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView? parent,
View v, int position, long id){
ImageView imageView = (ImageView) findViewById(R.id.image1);
imageView.setImageResource(images[position]);
}
});
}
public class ImageAdapter extends BaseAdapter{
private Context context;
public ImageAdapter(Context c)
{
context = c;
}
public int getCount(){
return images.length;
}
public Object getItem(int position){
return position;
}
public long getItemId(int position){
return position;
}
public View getView(int pos, View convertView, ViewGroup parent){
ImageView imageView;
if(convertView == null){
imageView = new ImageView(context);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setLayoutParams(new
Gallery.LayoutParams(150, 120));
}else
imageView = (ImageView)convertView;
imageView.setImageResource(images[pos]);
return imageView;
}}}
3. 버튼과 에디트 텍스트의 순서를 변경하면 결과는?
FrameLayout xmlns:android=http://schemas.android.com/apk/res/android
android:orientation=vertical
android:layout_width=fill_parent
android:layout_height=fill_parent
TextView
android:layout_width=fill_parent
android:layout_height=wrap_content
android:text=@string/hello/
EditText
android:text=EditText
android:id=@+id/EditText01
android:layout=width=wrap_content
android:layout=height=wrap-content/
Button
android:text=Button
android:id=@+id/Button01
android:layout_height=wrap_content
android:layout_width=fill_parent/
/FrameLayout