I have created this Android app where title and description are clickable ( each one - different click handler ) :
How did I do that ? like this :
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = activity.getLayoutInflater();
View rowView = Util.inflateXmlGetView(activity, R.layout.city_layout);
TextView txtCity = (TextView) rowView.findViewById(R.id.txtCity);
txtCity.setText(position + 1 + ") " + data[position]);
txtCity.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Util.Toast(getContext(), "txtCity");
}
});
... same for Title...
}
All ok and working.
But :
Question
How can I make the row ( the white background in each row ) also clickable ?
Notice : I could do it like this :
CustomArrayAdapter adapter = new CustomArrayAdapter(this,cities,imageIDs,descriptions);
l1 = (ListView) findViewById(R.id.list_view_1);
l1.setAdapter(adapter);
l1.setOnItemClickListener(new OnItemClickListener() {...})
But then : this click handler ^ will execute when I click on labels : title/description.
Goal :
Main label click : -> execute-> handler 1
Description label click : -> execute-> handler 2
Row white space click : -> execute-> handler 3
edit
Additional info :
This is the main layout :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="List_1" />
<ListView
android:id="@+id/list_view_1"
android:layout_width="fill_parent"
android:layout_height="match_parent" />
</LinearLayout>
This is the city layout : where each layout is in each row :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/icon"
android:layout_width="50dp"
android:layout_height="80dp"
android:layout_margin="20dp"
android:src="@drawable/f111" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/txtCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:textSize="30sp" />
<TextView
android:id="@+id/txtDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dsfsfd" android:layout_marginTop="10dp"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
0 comments:
Post a Comment