0

i have a CustomListView which is loaded with AsyncTask. I have a imageButton to the end of each row.

My probleme : When i click to my imageButton , nothing work. I tried many solution like this :

Android : how to set listener and get position of imagebutton click in a custom adapter

My ListView class who call AsyncTask :

public class listview extends Activity {

private ListView maListViewPerso;   
ImageButton imgButton;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ActionBar actionBar = getActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(Color
            .parseColor("#000000")));

    maListViewPerso = (ListView) findViewById(R.id.listviewperso);

    asyncTask asynchrone_task_tournee = new asyncTask(listview.this, maListViewPerso);
    asynchrone_task_tournee.execute();  

}

This is my imageButton where i want to get position and set a listener.. enter image description here

EDIT 1 (answer comment) this is my onPostExecute() and there is my SimpleAdapter :

@Override
protected void onPostExecute(JSONArray jArray) {        
    super.onPostExecute(jArray);

    JSONObject json_data=null;     
    HashMap<String, String> map;
    ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();

    this.pDialog.dismiss();     



      Log.i("JSON_TOURNER",jArray.toString());

      for(int i=0;i < jArray.length();i++)
      {             
            try {

                json_data = jArray.getJSONObject(i);

                 map = new HashMap<String, String>();
                 map.put("titre", json_data.getString("time"));
                 map.put("description", json_data.getString("date"));
                 map.put("begin_hour", json_data.getString("hour"));
                 map.put("end_hour", json_data.getString("hour"));


                 listItem.add(map);

            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }     
      }

      SimpleAdapter mSchedule = new SimpleAdapter (Mycontext, listItem, R.layout.list_type_tournee,
             new String[] {"titre", "description","begin_hour","end_hour"}, new int[] {R.id.miscellaneous, R.id.infos,R.id.begin_hour,R.id.end_hour});

      listview.setAdapter(mSchedule);


}
Sahil Mahajan Mj
  • 11,033
  • 8
  • 53
  • 100
Thomas Trabelsi
  • 330
  • 1
  • 8
  • 21
  • 1
    where is your `ListAdapter` code? you can implement it inside the `getView()` method. – SMR Feb 10 '14 at 11:19

2 Answers2

0

All right, if you use controls like ImageButton, CheckBox ,Button etc in a ListView then you would face problems discussed here and here.

To solve this you need to add android:focusable="false" in the xml of your ImageButton.

If the above doesn't work then you should add android:descendantFocusability="blocksDescendants" to the parent layout of your ImageButton and then implement onClickListener() for the ImageButton.

for more see this.

Hope it helps.

Community
  • 1
  • 1
SMR
  • 6,628
  • 2
  • 35
  • 56
  • I tried to implement onClickListener() for the ImageButton, and pet android:descendantFocusability="blocksDescendants" to the parent layout. But when i run the apps, it's crash directly – Thomas Trabelsi Feb 10 '14 at 14:11
0

I resolved my probleme . Finaly, i removed the imageButton, and i pet a frame layout in my linear layout, and i pet a listener on my listeView to open the dialog.

I pet android:descendantFocusability="blocksDescendants" too, in my linear parent of the frame layout

Thomas Trabelsi
  • 330
  • 1
  • 8
  • 21