-2

I'm developing and android app, and i'm having serious problems with listview.

At first I had an onItemClickListener and it worked well, but now, i've included some new features to the layout and it doesn't work.

my code is :

lv = (ListView) findViewById(R.id.listChap);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        Toast.makeText(CapituloList.this,"Pulsado",Toast.LENGTH_SHORT).show();
        Capitulo chap = (Capitulo) mAdapter.getItem(i);
        Intent mIntent = new Intent(CapituloList.this, MangaView.class);
        mIntent.putExtra("capitulo", chap);
        startActivity(mIntent);
    }
});

And in Capitulo Adapter I have:

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
    LayoutInflater inflater = (LayoutInflater)   mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    view  = inflater.inflate(R.layout.list_manga_item_view,null);
    TextView tv = (TextView) view.findViewById(R.id.nombre_manga);
    ImageButton ib = (ImageButton) view.findViewById(R.id.checked_icon);
    ImageButton ib2 = (ImageButton) view.findViewById(R.id.unchecked_icon);
    tv.setText(mItems.get(i).getCapitulo());
    return view;
}

Obviusly i want to diferientiate between touches on ib, ib2 and the rest of the Layout The visible result is: click on the URL, i have no reputation to post images https://i.stack.imgur.com/EU3o5.png

Thanks in advance

EDIT: SOLVED

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
    LayoutInflater inflater = (LayoutInflater)   mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    view  = inflater.inflate(R.layout.list_manga_item_view,null);
    TextView tv = (TextView) view.findViewById(R.id.nombre_manga);
    final Capitulo chap = (Capitulo) this.getItem(i);
    ImageButton ib = (ImageButton) view.findViewById(R.id.imageButton);
    ib.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(mContext,"Button1 pressed",Toast.LENGTH_LONG).show();
        }
    });
    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent mIntent = new Intent(mContext, MangaView.class);
            mIntent.putExtra("capitulo", chap);
            mContext.startActivity(mIntent);
        }
    });
    ImageButton ib2 = (ImageButton) view.findViewById(R.id.imageButton2);
    ib2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(mContext,"Button2 pressed",Toast.LENGTH_LONG).show();
        }
    });
    tv.setText(mItems.get(i).getCapitulo());
    return view;
}
  • Have you set the onItemClickListener on those buttons? – Victor Jun 16 '14 at 11:58
  • Nope, when it was just an TextView it did worked, but now, it dont recognise touches events – Pablo Arnau González Jun 16 '14 at 11:59
  • intenta ponerle un click listener a los imagebutton. Dices que ahora no reacciona al pulsar ningun objeto de la lista? – Victor Jun 16 '14 at 12:02
  • Try this answer, it solves a similar problem: detecting clicks on a widget in a listview row, not on the whole item http://stackoverflow.com/questions/24170236/android-listfragment-get-clicked-item-within-listitem/24170920#24170920 – DDsix Jun 16 '14 at 12:05
  • waht you want? are you want to click on imagebutton1 and imagebutton2 click event or want to whole list item click event detect – Vijay Rajput Jun 16 '14 at 12:06
  • There are three posible actions: First: Click whereever (not any of the buttons) and start a new Activity. Second Click the first button and mark as readed, Third: Click the second Button and download the chapter – Pablo Arnau González Jun 16 '14 at 12:12

1 Answers1

0
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
LayoutInflater inflater = (LayoutInflater) 
mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view  = inflater.inflate(R.layout.list_manga_item_view,null);
TextView tv = (TextView) view.findViewById(R.id.nombre_manga);
final Capitulo chap = (Capitulo) this.getItem(i);
ImageButton ib = (ImageButton) view.findViewById(R.id.imageButton);
ib.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Toast.makeText(mContext,"Button1 pressed",Toast.LENGTH_LONG).show();
    }
});
view.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Intent mIntent = new Intent(mContext, MangaView.class);
        mIntent.putExtra("capitulo", chap);
        mContext.startActivity(mIntent);
    }
});
ImageButton ib2 = (ImageButton) view.findViewById(R.id.imageButton2);
ib2.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Toast.makeText(mContext,"Button2 pressed",Toast.LENGTH_LONG).show();
    }
});
tv.setText(mItems.get(i).getCapitulo());
return view;
}