ImageView Action in ListView

0

Good evening,

I'm developing an application for android, and I have in my main screen a ListView and an Activity with two ImageView and a TextView, that this Activity is called in the main class that controls the ListView, until then all right.

I would like to know if it is possible to get one of the ImageViews when clicked (since it belongs to the ListView), take the ListView id in its onClick action.

Does anyone know if this is possible?

Follow the codes:

Main screen where you have ListView

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MyActivity"
>

<!-- As the main content view, the view below consumes the entire
     space available using match_parent in both dimensions. -->
<FrameLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >




    <ListView
        android:id="@+id/listViewPlacas"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal|top"
        android:divider="#FFFFFF"
        android:dividerHeight="4dp"
        android:layout_weight="1"
        android:listSelector="@drawable/list_selector"
        android:background="@drawable/fundo_list"
        />


</FrameLayout>

<!-- android:layout_gravity="start" tells DrawerLayout to treat
     this as a sliding drawer on the left side for left-to-right
     languages and on the right side for right-to-left languages.
     If you're not building against API 17 or higher, use
     android:layout_gravity="left" instead. -->
<!-- The drawer is given a fixed width in dp and extends the full height of
     the container. -->
<fragment android:id="@+id/navigation_drawer"
    android:layout_width="@dimen/navigation_drawer_width"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:name="checklist.system.cooper.br.syschecklist.NavigationDrawerFragment"
    tools:layout="@layout/fragment_navigation_drawer" />

Screen where items ListView

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<View
    android:id="@+id/Vbarra"
    android:layout_height="2dp"
    android:layout_width="335dp"
    android:background="#3929769f"
    android:visibility="gone" />

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    >

    <ImageView
        android:id="@+id/imagemview"
        android:layout_width="64dp"
        android:layout_height="47dp"
        android:src="@drawable/checklist"
        android:layout_gravity="top" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="38dp"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:id="@+id/txtPlacaPrincipal"
        android:layout_weight="0.40"
        android:textColor="#ff000000"
        android:textStyle="bold" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="46dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="0"
        android:id="@+id/txtQuantidade"
        android:layout_weight="0.22"
        android:textColor="#ff000000"
        android:textStyle="bold" />

    <ImageView
        android:id="@+id/imagemAdd"
        android:layout_width="64dp"
        android:layout_height="47dp"
        android:src="@drawable/ic_action_add_to_queue"
        android:layout_gravity="top"
        android:onClick="addCheckList"/>


</LinearLayout>

ImageView call code

public void addCheckList(View v)
{

}

Thank you

    
asked by anonymous 07.07.2014 / 01:35

2 answers

2

Try this

listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapter, View view, int position, long arg3) {
            // TODO Auto-generated method stub

        }
    });
    
28.07.2014 / 22:10
0

Place the click event on the adapter of your listView:

See if that helps you.

public class ListAdapter extends ArrayAdapter<Item> {

public ListAdapter(Context context, int textViewResourceId) {
    super(context, textViewResourceId);
}

public ListAdapter(Context context, int resource, List<Item> items) {
    super(context, resource, items);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    View v = convertView;

    if (v == null) {

        LayoutInflater vi;
        vi = LayoutInflater.from(getContext());
        v = vi.inflate(R.layout.itemlistrow, null);

    }

        final Item item = getItem(position);

        TextView txtQuantidade = (TextView) v.findViewById(R.id.txtQuantidade);
        TextView txtPlacaPrincipal= (TextView) v.findViewById(R.id.txtPlacaPrincipal);
        ImageView imagemAdd= (ImageView )v.findViewById(R.id.imagemAdd);

         txtQuantidade.setText(String.valueOf(item.getQtde());
         txtPlacaPrincipal.setText(item.getPlacaPrincipal());

        imagemAdd.setOnClickListener(new OnClickListener() {
         public void onClick(View v)
         {
             //evento

         } 
           });




    return v;

}
    
07.07.2014 / 19:10