Today I have a headache: I wrote Listview.setonitemclicklistener () in the OnCreate () method in activity.
But nothing happens when you click on the ListView item after running the emulator, but this does not happen in the past.
Baidu later found the problem: (Reference link: http://ming.highgic.com/?p=198)
the original ListView of the Item It 's inside . Button , you need to XML settings in the layout file Button property, where focusable is key:
Android:focusable= "false" android:clickable= "false" Android:focusableintouchmode= "false"
Below the Sun code:
//activity the OnCreate () method
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (r.layout.allcourses);
ListView = (ListView) This.findviewbyid (R.ID.ALLCOURSELISTV);
Madapter = new Simpleadapter (this, GetData (),
R.layout.allcourselistviewitem, new string[] {"Image",
"title", "Tvgo"}, new int[] {R.id.allcourseimagev,
R.ID.ALLCOURSETEXTEXTV, R.id.allcoursego});
Listview.setadapter (Madapter);
Listview.setonitemclicklistener (New Onitemclicklistener () {
@Override
public void Onitemclick (adapterview<?> parent, view view,
int position, long ID) {
Intent Intent = new Intent (Allcourseactivity.this,
Classificationcourseactivity.class);
String[] name = {" Literature", "philosophy", "Art", "History", "economics", "Education", "physiology",
"Agronomy", "Jurisprudence", "psychology", "medicine", "military", "management", "Architecture and Engineering", "Internet"};
Intent.putextra ("Textviewname", Name[position]);
StartActivity (Intent);
. Show ();
}
});
}
// the above simpleadapter data that needs to be bound
Public listMhashmaps = new arraylist
Map = new hashmap<string, object> ();
Map.put ("image", r.drawable.wx);
Map.put ("title", " literature");
Mhashmaps.add (map);
Map = new hashmap<string, object> ();
Map.put ("image", R.DRAWABLE.ZX);
Map.put ("title", " philosophy");
Mhashmaps.add (map);
Map = new hashmap<string, object> ();
Map.put ("image", R.drawable.ys);
Map.put ("title", " art");
Mhashmaps.add (map);
Map = new hashmap<string, object> ();
Map.put ("image", r.drawable.ls);
Map.put ("title", " history");
Mhashmaps.add (map);
Map = new hashmap<string, object> ();
Map.put ("image", R.DRAWABLE.JJX);
Map.put ("title", " economy");
Mhashmaps.add (map);
Map = new hashmap<string, object> ();
Map.put ("image", R.drawable.jyx);
Map.put ("title", " Education");
Mhashmaps.add (map);
Map = new hashmap<string, object> ();
Map.put ("image", r.drawable.lk);
Map.put ("title", " physiology");
Mhashmaps.add (map);
Map = new hashmap<string, object> ();
Map.put ("image", R.DRAWABLE.LX);
Map.put ("title", " agronomy");
Mhashmaps.add (map);
Map = new hashmap<string, object> ();
Map.put ("image", r.drawable.fx);
Map.put ("title", " jurisprudence");
Mhashmaps.add (map);
Map = new hashmap<string, object> ();
Map.put ("image", R.DRAWABLE.XLX);
Map.put ("title", " psychology");
Mhashmaps.add (map);
Map = new hashmap<string, object> ();
Map.put ("image", R.drawable.yx);
Map.put ("title", " Medicine");
Mhashmaps.add (map);
Map = new hashmap<string, object> ();
Map.put ("image", r.drawable.js);
Map.put ("title", " military");
Mhashmaps.add (map);
Map = new hashmap<string, object> ();
Map.put ("image", R.DRAWABLE.GLX);
Map.put ("title", " Management");
Mhashmaps.add (map);
Map = new hashmap<string, object> ();
Map.put ("image", r.drawable.gk);
Map.put ("title", " Architecture and Engineering");
Mhashmaps.add (map);
Map = new hashmap<string, object> ();
Map.put ("image", R.DRAWABLE.JH);
Map.put ("title", " Internet");
Mhashmaps.add (map);
return mhashmaps;
}
//listview The XML file for each item in the ListView (the XML file for the list does not need to be posted)
<?xml version= "1.0" encoding= "Utf-8"?>
< LinearLayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:background= "@drawable/gradient_bg_hover"
android:orientation= "Horizontal" >
<imageview
Android:id= "@+id/allcourseimagev"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_gravity= "Center"
Android:layout_margin= "5DP"
android:src= "@drawable/jh"/>
<textview
Android:id= "@+id/allcoursetextextv"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:layout_marginleft= "37DP"
android:layout_weight= "1"
Android:gravity= "Center_vertical"
android:text= " All Courses"
Android:textcolor= "#000000"
Android:textsize= "18sp"/>
<button// That 's the button that got me busy, half the day .
Android:id= "@+id/allcoursego"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_gravity= "Center"
android:layout_marginright= "17DP"
Android:gravity= "Right"
Android:focusable= "false"
Android:clickable= "false"
Android:focusableintouchmode= "false"
android:background= "@drawable/turnright"
/>
</LinearLayout>