#android #onclick #tablelayout #tablerow
#Android #onclick #tablelayout #tablerow
Вопрос:
Как я могу щелкнуть каждую строку и столбец моего TabelLayout
?.
Я не знаю, как обрабатывать событие щелчка в TableLayout
. Если я щелкну строку, в которой хочу показывать изображения, я думаю, мне нужно обработать событие щелчка. Я в замешательстве, пожалуйста, помогите мне, друзья.
Это мой дизайн xml и исходный код xml.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray"
android:padding="10dp">
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/white">
<ImageView
android:id="@ id/imgPicture4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:src="@drawable/icon" >
</ImageView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:orientation="vertical"
android:paddingLeft="10dp" >
<TextView
android:id="@ id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name : Tom"
android:textColor="@android:color/black" >
</TextView>
<TextView
android:id="@ id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Company : TCS"
android:textColor="@android:color/black" >
</TextView>
<TextView
android:id="@ id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone : 12345"
android:textColor="@android:color/black" >
</TextView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@android:color/white">
<ImageView
android:id="@ id/imgPicture4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:src="@drawable/icon" >
</ImageView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:orientation="vertical"
android:paddingLeft="10dp" >
<TextView
android:id="@ id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name : Tom"
android:textColor="@android:color/black" >
</TextView>
<TextView
android:id="@ id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Company : Infosys"
android:textColor="@android:color/black" >
</TextView>
<TextView
android:id="@ id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone : 45678"
android:textColor="@android:color/black" >
</TextView>
</LinearLayout>
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:gravity="center_horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/white">
<ImageView
android:id="@ id/imgPicture4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:src="@drawable/icon" >
</ImageView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:orientation="vertical"
android:paddingLeft="10dp" >
<TextView
android:id="@ id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name : Tom"
android:textColor="@android:color/black" >
</TextView>
<TextView
android:id="@ id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Company : TCS"
android:textColor="@android:color/black" >
</TextView>
<TextView
android:id="@ id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone : 12345"
android:textColor="@android:color/black" >
</TextView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@android:color/white">
<ImageView
android:id="@ id/imgPicture4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:src="@drawable/icon" >
</ImageView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:orientation="vertical"
android:paddingLeft="10dp" >
<TextView
android:id="@ id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name : Tom"
android:textColor="@android:color/black" >
</TextView>
<TextView
android:id="@ id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Company : Infosys"
android:textColor="@android:color/black" >
</TextView>
<TextView
android:id="@ id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone : 45678"
android:textColor="@android:color/black" >
</TextView>
</LinearLayout>
</LinearLayout>
</TableRow>
</TableLayout>
</ScrollView>
Комментарии:
1. вы хотите щелкнуть по каждому элементу или строке? в строке вашей таблицы есть 2 элемента.
2. я хочу щелкнуть каждый элемент yashwanth….
3. Действительно ли содержимое вашего TableLayout статично? Вам нужно разработать свою деятельность, используя TableLayout в качестве контейнера, и использовать адаптер для привязки реальных данных к вашему представлению. Используя этот подход, вы могли бы реализовать метод onItemClick…
4. планируете ли вы загружать данные динамически? или через xml?
5. Пожалуйста, дайте мне пример ссылки renaud. это очень помогает мне….