0
Good night,
I’m developing an application for android, and I have on my main screen a Listview and an Activity with two Imageview and a Textview, this Activity is called in the main class that controls Listview, until then everything right.
What I would like to know is if it is possible to make one of the Imageview when clicked (since it belongs to Listview), take the Listview id in your onClick action.
Does anyone know if that’s possible?
Follows the codes:
Main screen where has the 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 have the items of 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>
Code of call from Imageview
public void addCheckList(View v)
{
}
Thank you
Try following this tutorial: http://cyrilmottier.com/2011/11/23/listview-tips-tricks-4-add-several-clickable-areas/. With it I was able to make clickable areas inside an item on
ListView
– Wakim