0

thank you for your time.

I have a list of Strings that a display inside a gridview using an ArrayAdapter. Some of those Strings are long and take too much room. I want to limit the height of each grid cell to 1 line and be able to read the full string when i'm clicking on this cell.

Here's my gridview.xml :

    <GridView
    android:id="@+id/songSelectionGrid_grid"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@id/songSelectionGrid_button_back"
    android:columnWidth="90sp"
    android:horizontalSpacing="10dp"
    android:numColumns="3"
    android:verticalSpacing="10dp" />

and here is my textview inside my gridview :

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceListItemSmall" 
android:maxLines = "1"
android:scrollbars = "horizontal"/>

How can i make the Strings scroll horizontally ? I've tried a onItemClickListener on the gridview followed by a "setMovementMethod" on the view, but it need to be a TextView and casting it doesn't seem to work

Thanks !

P.h. Dvrgne
  • 131
  • 1
  • 1
  • 7
  • What about wrapping that TextView into a ScrollView? See http://stackoverflow.com/questions/6674341/how-to-use-scrollview-in-android – Pablo Lozano Jun 13 '13 at 15:57
  • The application instantly dies when the activity is started, I don't really know why. Maybe GridView doesn't really like having a scrollview inside of each cell ? – P.h. Dvrgne Jun 14 '13 at 07:18
  • I don't think that's the problem, GridView only knows it has Views inside, but not the exact type... try to check the logs and see why it's dying – Pablo Lozano Jun 14 '13 at 07:32
  • Log says I need to supply a resource ID for a textView but I don't understand what's exactly wrong since the application is not dying when there aren't scrollview :( EDIT : well it seems the error comes from the arrayList from which i'm populating my gridView, the constructor isn't the right one. – P.h. Dvrgne Jun 14 '13 at 07:48
  • I've tried different constructor for the ArrayAdapter but it appears that the issue comes from the fact that a gridView only allows to have 1 view in each cell (one textView but not one scrollview+one textview). Since I want to have a picture+a scrollable textview in each of my gridview cell, i'm not sure i'm on the right way to achieve this. – P.h. Dvrgne Jun 14 '13 at 08:43

1 Answers1

0

Ok so I've managed to make it work as intended : gridview displaying multiple albums (cover picture + horizontally scrollable text). To do so, I've created my own GridAdapter with the following getView() :

    public View getView(int position, View convertView, ViewGroup parent)
{
    // TODO Auto-generated method stub
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View gridView = null;
    convertView = null;
    if(convertView == null)
    {
        gridView = new View(context);
        gridView = inflater.inflate(R.layout.gridtextview, null);
        TextView textView = (TextView) gridView.findViewById(R.id.gridView_text);

        textView.setText(textArray[position]);
        Log.i("GridAdapter","textView.getText : 
    }
    return gridView;
}

The gridView I am populating is composed of the following :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridView_topLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >

<ImageView
    android:id="@+id/gridView_image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:contentDescription="@string/gridTextView_Album"
    android:src="@drawable/ic_launcher" />

<HorizontalScrollView
    android:id="@+id/gridView_horizontalScroll"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="left"
    android:clipChildren="true"
    android:fillViewport="true"
    android:scrollbars="none" >

    <RelativeLayout
        android:id="@+id/gridView_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/gridView_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:isScrollContainer="true"
            android:paddingBottom="10sp"
            android:singleLine="true" />
    </RelativeLayout>
</HorizontalScrollView>

I am not sure this is the best way of doing it but it does work. But still, keep in mind I'm still a beginner in android dev :)

P.h. Dvrgne
  • 131
  • 1
  • 1
  • 7