I've got a custom Adapter, because I have two Textviews in a row. First of all I want only the left sides TextViews clickable and disable click event for the right side.
layout_list_xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView style="@style/TextDesign"
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/left" />
<TextView style="@style/TextDesign"
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="@+id/right" />
</RelativeLayout>
</LinearLayout>
Custom Adapter:
public class CustomAdapter extends BaseAdapter {
Context context;
List<Occurence> occurenceList;
TextView left, right;
public CustomAdapter(Context context, List<Occurence> occurenceList) {
this.context = context;
this.occurenceList = occurenceList;
}
@Override
public int getCount() {
return occurenceList.size();
}
@Override
public Object getItem(int position) {
return occurenceList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater=LayoutInflater.from(context);
View v=inflater.inflate(R.layout.layout_list,parent,false);
left=(TextView) v.findViewById(R.id.left);
right=(TextView) v.findViewById(R.id.right);
left.setText(occurenceList.get(position).singleNumber);
right.setText(occurenceList.get(position).occurence+" occurence");
v.setTag(occurencekList.get(position).getId());
return v;
}
@Override
public boolean areAllItemsEnabled() {
return super.areAllItemsEnabled();
}
@Override
public boolean isEnabled(int position) {
return super.isEnabled(position);
}
}
So when the User clicks on the TextView I want to disable the click for that TextView on the List. The value of the clicked TV will moved to another TextView as a SpannableString where can I perform another action. That means if the User clicks on that SpannableString that will remove that SpannableString and reenable the click action for that ListItem which is disabled.
I attached a picture below to see the result.
I've read about that I should put an if statement in the Override method called isEnabled in the adapter class but I need the concrete solution.