Custom Base Adapter



I have created a ViewFlow that switches ImageView horizontally on swipe. Everything works fine. However i am adding a Content Description to the current ImageView so TalkBack option can read a content description. The thing is that after the 4th image TalkBack is not reading the content. What i am missing here?


Here is the setup:



viewFlow.setAdapter(new ImageAdapter(this), 0);


viewFlow xml:



<org.taptwo.android.widget.ViewFlow
android:id="@+id/viewflow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:contentDescription="@null"
android:layout_alignParentLeft="true"
android:layout_below="@+id/relativeLayout1"
android:padding="3dp"
app:sidebuffer="3" >

</org.taptwo.android.widget.ViewFlow>


image_item.xml:



<LinearLayout
xmlns:android="http://ift.tt/nIICcg"
android:layout_width="fill_parent" android:isScrollContainer="true"
android:layout_height="fill_parent" android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true">

<ImageView
android:id="@+id/imgView"
android:contentDescription="@null"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter" />

</LinearLayout>


Here is the CustomAdapter:



public class ImageAdapter extends BaseAdapter {

private Context context;
private LayoutInflater mInflater;


private static final int[] ids = {
//These are Dummy Data dont stick to naming convention
R.drawable.1,
R.drawable.2,
R.drawable.3,
R.drawable.4,
R.drawable.5,
R.drawable.6,
R.drawable.7 };

private static final String[] descriptions = {
"Content 1",
"Content 2",
"Content 3",
"Content 4",
"Content 5",
"Content 6",
"Content 7"
};

public ImageAdapter(Context context) {
this.context = context;
}

@Override
public int getCount() {
return ids.length;
}

@Override
public Object getItem(int position) {
return position;
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);


if (convertView == null) {
convertView = mInflater.inflate(R.layout.image_item, null);
}

((ImageView) convertView.findViewById(R.id.imgView)).setContentDescription(descriptions[position]);
((ImageView) convertView.findViewById(R.id.imgView)).setImageResource(ids[position]);

return convertView;
}
}

No comments:

Post a Comment