0

I'am trying implement on my project one xml file that's contains: a textview, gridview, and one back button, but here the code:

<?xml version="1.0" encoding="UTF-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:mask="http://schemas.android.com/apk/res/br.com.example.sgm"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/Black"
    android:screenOrientation="portrait" >



    <TextView
    android:id="@+id/TextView01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="20dp"
    android:layout_marginTop="10dp"
    android:text="Código                 Data"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="@color/LSGray" />






    <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="410dp"
    android:onClick="bvoltar"
    android:text="     Voltar     "
    android:textColor="@color/Snow" />

    <ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="350dp"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="50dp" >

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >



    <GridView
    android:id="@+id/gridview"
    android:layout_width="match_parent"
    android:layout_height="345dp"
    android:numColumns="1" >

    </GridView>

    </LinearLayout>
    ScrollView>

</RelativeLayout>

This should be a little text on top, a grid that will show fields from one db table, and a button to exit, inside the grid a scroll.... but when I run the project and go to this screen, the scroll doesn't work, the grid load and show the entrys, but if try move the scroll this close my apk, anyone know how fix it?

here's adapter:

public class DataAdapter extends BaseAdapter

{

  Context mContext;


//      
//      private String [] codigo = new String[100];
//      private String [] data = new String[100];

  private LayoutInflater mInflater;

  public int cont;

  public DataAdapter(Context c)

  {

         mContext=c;

         mInflater = LayoutInflater.from(c);

  }

  public int getCount()

  {
      PersistenceHelper per = PersistenceHelper.getInstance(mContext);
        List<Ocorrencia> lOco;
            lOco = per.listarOcorrencia();
        return lOco.size();

  }

  public Object getItem(int position)

  {

         return position;

  }

  public long getItemId(int position)

  {

         return position;

  }

  public View getView(int position, View convertView, ViewGroup parent)

  {

         ViewHolder holder=null;

         if(convertView==null)

         {

                convertView = mInflater.inflate(R.layout.customgrid,
                                                               parent,false);

                holder = new ViewHolder();

                holder.txtCodigo=(TextView)convertView.findViewById(R.id.txtCodigo);

                holder.txtCodigo.setPadding(10, 10, 10 , 10);

                holder.txtData=(TextView)convertView.findViewById(R.id.txtData);

                holder.txtData.setPadding(10, 10, 10, 10);

                if(position==0)

                {                             

                      convertView.setTag(holder);

                }

         }

         else

         {

                holder = (ViewHolder) convertView.getTag();

         }
         PersistenceHelper per = PersistenceHelper.getInstance(mContext);

         List<Ocorrencia> lOco = per.listarOcorrencia();
         setCont(lOco.size());

         String [] codigo = new String[getCont()];
         String [] data = new String[getCont()];

         for(int x=0; x<getCont(); x++){
             codigo[x] = lOco.get(x).getCodigo();
             data[x] = lOco.get(x).getData();  
             }  

         holder.txtCodigo.setText(codigo[position]);

         holder.txtData.setText(data[position]);

         getCount();

         return convertView;


  }

  static class ViewHolder

  {        

         TextView txtCodigo;        

         TextView txtData;               

  }

public int getCont() {
    return cont;
}

public void setCont(int cont) {
    this.cont = cont;
}



}

and if was necessary...

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical">

<TableLayout android:id="@+id/TableLayout01"

          android:layout_height="wrap_content"

          android:layout_width="fill_parent">


   <TableRow
       android:id="@+id/TableRow01"
       android:layout_width="wrap_content"
       android:layout_height="fill_parent" >




    <TextView
        android:id="@+id/txtCodigo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="Codigo"
        android:textColor="@color/LSGray" />


    <TextView
        android:id="@+id/txtData"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="                  Data"
        android:textColor="@color/Snow" />

   </TableRow>

</TableLayout>

</LinearLayout>

doesn't have a error on logcat cause this this code I have change things, but the problem is because is no close more but, this just show a little piece from entrys of db, doesn't show all entrys, and I cannot change the gridview to fill parent on width and height, how can I put the grid to increase size each new entrys?

UPDATE 1
when I delete scrollview by MM-BB answer
logcat error:

06-06 05:14:17.287: E/AndroidRuntime(828): FATAL EXCEPTION: main
06-06 05:14:17.287: E/AndroidRuntime(828): java.lang.NullPointerException
06-06 05:14:17.287: E/AndroidRuntime(828):  at com.example.sgm.DataAdapter.getView(DataAdapter.java:125)
06-06 05:14:17.287: E/AndroidRuntime(828):  at android.widget.AbsListView.obtainView(AbsListView.java:2255)
06-06 05:14:17.287: E/AndroidRuntime(828):  at android.widget.GridView.makeAndAddView(GridView.java:1331)
06-06 05:14:17.287: E/AndroidRuntime(828):  at android.widget.GridView.makeRow(GridView.java:331)
06-06 05:14:17.287: E/AndroidRuntime(828):  at android.widget.GridView.fillDown(GridView.java:283)
06-06 05:14:17.287: E/AndroidRuntime(828):  at android.widget.GridView.fillGap(GridView.java:243)
06-06 05:14:17.287: E/AndroidRuntime(828):  at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5040)
06-06 05:14:17.287: E/AndroidRuntime(828):  at android.widget.AbsListView.scrollIfNeeded(AbsListView.java:3197)
06-06 05:14:17.287: E/AndroidRuntime(828):  at android.widget.AbsListView.onTouchEvent(AbsListView.java:3471)
06-06 05:14:17.287: E/AndroidRuntime(828):  at android.view.View.dispatchTouchEvent(View.java:7127)
06-06 05:14:17.287: E/AndroidRuntime(828):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2170)
06-06 05:14:17.287: E/AndroidRuntime(828):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1905)
06-06 05:14:17.287: E/AndroidRuntime(828):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
06-06 05:14:17.287: E/AndroidRuntime(828):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
06-06 05:14:17.287: E/AndroidRuntime(828):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
06-06 05:14:17.287: E/AndroidRuntime(828):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
06-06 05:14:17.287: E/AndroidRuntime(828):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
06-06 05:14:17.287: E/AndroidRuntime(828):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
06-06 05:14:17.287: E/AndroidRuntime(828):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
06-06 05:14:17.287: E/AndroidRuntime(828):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
06-06 05:14:17.287: E/AndroidRuntime(828):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
06-06 05:14:17.287: E/AndroidRuntime(828):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
06-06 05:14:17.287: E/AndroidRuntime(828):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
Mahdi-bagvand
  • 1,396
  • 19
  • 40

1 Answers1

0

1-Gridview dont need scrollView this is a warning that eclipse show when you use gridview in scrollview

The vertically scrolling ScrollView should not contain another vertically scrolling widget (GridView)

2-change ScrollView> to </ScrollView>

Mahdi-bagvand
  • 1,396
  • 19
  • 40
  • @ Marcelo Vilas Boas Marin if you delete scrollview your problem will be solved – Mahdi-bagvand Jun 06 '13 at 05:16
  • I tried this things, I delete scrollview, and I put on a relative activity the grid view, but the logcat report's this (I'll edit with logcat error): – Marcelo Vilas Boas Marinho Jun 06 '13 at 05:18
  • Saddly doesn't solve =\ .... I still with problem, now the aplication turn back to close when try click and roll down the screen, with the logcat error that I edit on the topic... I need, at one space, a gridview that I can roll each entry that I have, example: 50 entrys, roll down the screen since the first till the last one, on the final of screen to exit that. – Marcelo Vilas Boas Marinho Jun 06 '13 at 05:28
  • @ Marcelo Vilas Boas Marinho by delete scrollview and LinearLayout and some change your xml file will be ok. Logcat error show a java file error – Mahdi-bagvand Jun 06 '13 at 05:36
  • @ Marcelo Vilas Boas Marinho Is My answer Ok? you didnt accept it? – Mahdi-bagvand Jun 07 '13 at 16:58