J'ai écrit un adaptateur personnalisé pour une liste, mais quand j'ai essayé d'implémenter l'événement de clic pour l'élément de liste, j'ai trouvé qu'il ne répondait pas, je serai heureux si quelqu'un me propose une solution.setOnItemClickListener ne répond pas pour ListView personnalisé
public class TourList extends ListActivity {
....
setContentView(R.layout.tourlist);
.....
getListView().setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
//i couldn't reach here
Log.v(TAG,"did u get me");
}
});
adap = new MyAdapter(TourList.this,mylist);
getListView().setAdapter(adap);
et mon adaptateur personnalisé est
private class MyAdapter extends BaseAdapter {
ArrayList<HashMap<String,String>> elements;
Context ctx;
public MyAdapter(Context context, ArrayList<HashMap<String,String>> mylist) {
this.elements=mylist;
this.ctx=context;
}
public boolean isEnabled(int position){
return true;
}
@Override
public int getCount() {
return elements.size();
}
@Override
public Object getItem(int position) {
return elements.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (convertView == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.rowfor_tourlist, null);
}
TextView in = (TextView)v.findViewById(R.id.intro);
TextView du = (TextView)v.findViewById(R.id.duration);
TextView pf = (TextView)v.findViewById(R.id.price);
TextView pn = (TextView)v.findViewById(R.id.product);
WebView wv=(WebView)v.findViewById(R.id.photo);
in.setText(Html.fromHtml(mylist.get(position).get("Intro")));
du.setText(mylist.get(position).get("Duration"));
pf.setText(mylist.get(position).get("Price"));
pn.setText(mylist.get(position).get("Product"));
wv.getSettings().setJavaScriptEnabled(true);
wv.loadUrl(mylist.get(position).get("ImageURL"));
return v;
}
}//class
et mon fichier tourlist.xml ressemble
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
....
>
<ListView android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/white"
android:cacheColorHint="#00000000"
android:layout_weight="1"
/>
</...>
merci samuh je vais vérifier – ganesh