}
public void onItemClick(AdapterView<?> a0, View a1, int a2, long a3) {
// TODO Auto-generated method stub
t1.setText("Select: "+a2+" from "+a0.getCount()+"; id="+ia.getItem(a2));
}}
3.5 ³ GridView
2. ³ Gallery.
MyImageAdapter.java:
public View getView(int position, View convertView, ViewGroup parent){
ImageView v;
v = new ImageView(c); v.setImageResource(im[position]); v.setPadding(20, 20, 20, 20);
v.setLayoutParams(new Gallery.LayoutParams(140, 140));
v.setScaleType(ImageView.ScaleType.FIT_XY); return v;
}
Main.java
ᒺ:
final Gallery gv = (Gallery) findViewById(R.id.gv);
3.6 ³ Gallery
Android-, ListView. . .
. *.xml , (, activity_main.xml item.xml);
*.java : 1) , (, myobject, string str int image); 2) (, ItemAdapter.java) :
public ItemAdapter(Context _c, ArrayList<myobject> _ob)
{
c = _c; ob =_ob;
layoutinf = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
getView, :
publicViewgetView(int pos, View cv, ViewGroup parent){
View v = cv; if (v==null){
v=layoutinf.inflate(R.layout.item,parent,false);
}
myobject obs = getObject(pos);
((TextView) v.findViewById(R.id.t)).setText(obs.str);
((ImageView)v.findViewById(R.id.im)).setImageResource(ob s.image);
returnv;
}
3) , , setOnItemClickListener(android.widget.AdapterView.*).
, ;
;
;
;
.
1. () ?
2. ?
3. ArrayAdapter?
4. ᒺContext.
5. ᒺLayoutInflater.
6. ³AutoCompleteTextView.
7. ³MultiAutoCompleteTextView.
8. ³ListView.
9. ³Spinner.
10.³ .
4
Ͳֲ ̲ ò
: 䳺 Android- ᒺ Intent. Activity Activity extra- ᒺIntent.
|
|
4.1 Android
Android , , ( ) . .
. ., , , . , 볠 ( , ..) , - . . Android ' . , ,.
.
Android . . . :
(Foreground Process). , 䳺 , ᒺ Service BroadcastReceiver ᒺ;
(Visible Process) . Activity, , ;
(Service Process) , Service ;
(Background Process) , Activity, ;
(Empty Process) . , .
Activity
Activity :
(active) Activity ;
(paused) Activity , ;
(stopped) Activity Activity
: onCreate() Activity, onRestart() Activity, onStart() Activity, onResume()
䳿 Activity, onPause() , Activity, onStop() , Activity , onDestroy() Activity. ֳ Activity, 䳿 Activity. : protected void onPause(){ super.onPause(); }
4.3 Activity ᒺ Intent
|
|
Android-, Activity, ᒺ Intent. 栠 . Android Activity, Intent . ᒺ Intent :
Intent ;
Intent .
Intent , , Activity Activity .
Intent . Intent.
Android Activity . Activity , Activity Activity. ϳ , Activity Activity, .
4.4 Activity ᒺIntent
ᒺ Intent , . Activity, ᒺ Intent Activity. setComponent(), setClass() setClassName(). Activity, ᒺ Intent Context.startActivity(). ᒺ Intent, Activity, . , Activity NewActivity :
Intent intent = new Intent();
// intent.setClass(getApplicationContext(),
NewActivity.class);
// startActivity(intent);
Activity, . Project Explorer AndroidManifest.xml Application. Application Nodes
New Activity. Application Nodes Activity. , Attributes for Activity. Name Browse Activity (NewActivity). ϳ AndroidManifest.xml <activity> android:name = NewActivity.