Custom ViewGroup, GridView, and SimpleCursorAdapter

I need to display data in 3 textviews, inside each grid item, but also I want each grid item to be square. Also the cursoradapter is all based on a search.

Based on my necessities I found by research that I should be creating my own viewgroup for each grid item and setting the height to be the same as the width (in onMeasurement), which produces proper squares. But now my data from the cursoradapter will not show up in the views.

I can tell that the cursoradapter is being referenced because the number of white boxes in the gridview changes depending on what I search.

Where am I going wrong?

<ubiquia.sqbxsync.main.GridViewGroup
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff">

<RelativeLayout
    android:id="@+id/gridLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:ellipsize="end"
        android:singleLine="true"
        android:text="TextView"
        android:textSize="15dp"
        android:textColor="#ff000000" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView1"
        android:layout_marginLeft="10dp"
        android:ellipsize="end"
        android:singleLine="true"
        android:text="TextView"
        android:textSize="11dp"
        android:textColor="#ff000000" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView2"
        android:layout_marginLeft="10dp"
        android:ellipsize="end"
        android:singleLine="true"
        android:text="TextView"
        android:textSize="11dp"
        android:textColor="#ff000000" />

</RelativeLayout>

package ubiquia.sqbxsync.main;

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;

public class GridViewGroup extends ViewGroup {

    public GridViewGroup(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
     // Do nothing   
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, widthMeasureSpec);
    }  
}

My CursorAdapter

public class GridCursorAdapter extends CursorAdapter {

    public GridCursorAdapter(Context context, Cursor c) {
        super(context, c);
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View gridView = inflater.inflate(R.layout.grid_item, null, true);
        return gridView;
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        TextView tv1 = (TextView) view.findViewById(R.id.textView1);
        TextView tv2 = (TextView) view.findViewById(R.id.textView2);
        TextView tv3 = (TextView) view.findViewById(R.id.textView3);
        tv1.setText(cursor.getString(cursor.getColumnIndexOrThrow("trackingnumber")));
        tv2.setText(cursor.getString(cursor.getColumnIndexOrThrow("recipient_name")));
        tv3.setText(cursor.getString(cursor.getColumnIndexOrThrow("carrier_name")));
    }
}

Answers


I found out that after changing my extends to LinearLayout and writing in the super.onLayout(changed,l,t,r,b); it now shows my layout in the square that I wanted.


Need Your Help

Multipart Form Upload Image and Json

angularjs forms multipart-form

Bit stuck on this one, need to upload an image and json together using a multipart form.. not sure how to sent the content type headers or upload the image.. think i need to convert to blob.. at the

Building an activity from button click

android json android-intent

I build a UI based on JSON Objects sent in a method. Each time the method runs, a new row is added to the UI. I need my chartsButtonListener to be able to access the JSONObject question.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.