0

I have to view the data of a SQLite database in a table, now the problem is that all the gridView sample that I have seen are implemented with a single array that defines all data of the table

public class GridViewDemo extends Activity implements
        AdapterView.OnItemClickListener {

    TextView selection;
    String[] items = { "this", "is", "a", "really", "really2", "really3",
            "really4", "really5", "silly", "list" };

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);
        selection = (TextView) findViewById(R.id.selection);

        GridView gv = (GridView) findViewById(R.id.grid);

        ArrayAdapter<String> aa = new ArrayAdapter<String>(
                this,
                android.R.layout.simple_list_item_1, 
                items );

        gv.setAdapter(aa);
        gv.setOnItemClickListener(this);
    }

    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
        selection.setText(items[position]);
    }

}// class

at the link

Because I don't know how many rows will contains the data set selected by the user I should implement a gridView that receives different data arrays for each column.

Es

String dataColumn1[]=....
String dataColumn2[]=....
String dataColumn3[]=....

Or alternatively a method that limit the rows to a specified int, so also with a single array I could solve my problem.

AndreaF
  • 11,975
  • 27
  • 102
  • 168

1 Answers1

0

I should implement a gridView that receives different data arrays for each column.

You could easily implement this by making your own custom adapter and getting the cell item from the correct data array using the position parameter in the getView method. The catch is that you need to find out which of the column has the biggest number of items and insert fake items in the other data arrays to match that number so you keep the GridView in the correct state.

Or alternatively a method that limit the rows to a specified int, so also with a single array I could solve my problem.

I didn't understand this, the number of rows in the GridView is predetermined by the number of columns and the available data(if you have set 5 columns and you have 6 data items, you'll have 2 rows in the GridView).

You may also want to look at implementing the table with a ListView(I've answered a question that might be useful for this).

Community
  • 1
  • 1
user
  • 86,916
  • 18
  • 197
  • 190