I have problem, friends.
i had the application about grid view.
but error and can't view data.

+++++++++ main.xml ++++++++++++++++


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android";
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  >
  <TextView
     android:id="@+id/selection"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     />
  <GridView
     android:id="@+id/grid"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:verticalSpacing="35px"
     android:horizontalSpacing="5px"
     android:numColumns="auto_fit"
     android:columnWidth="100px"
     android:stretchMode="columnWidth"
     android:gravity="center"
     />
</LinearLayout>


+++++++++++++++++ row.xml +++++++++++++++++++++++++++++++

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/widget0"
android:orientation="horizontal"
android:layout_toRightOf="@android:id/icon"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
xmlns:android="http://schemas.android.com/apk/res/android";
>
<com.DataGrid.ListItemView
android:id="@+id/title"
android:layout_height="wrap_content"
android:layout_width="150px"
android:text="Title"
android:textSize="10sp"
android:textStyle="bold"
android:textColor="#ff000000"
/>


+++++++++++++++++ book.java +++++++++++++++++++++++++

package qi.com.DataGrid;

public class Book {
        String title;
    String author;

    public Book(String title, String author) {
        this.title = title;
        this.author = author;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getAuthor() {
        return author;
    }
    public void setAuthor(String author) {
        this.author = author;
    }

}


++++++++++++++++++ ListView.java ++++++++++++++++++++++++++


package qi.com.DataGrid;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;

public class ListItemView extends TextView {
    private boolean isHeader = false;
    private Paint linePaint;

    public ListItemView(Context context, AttributeSet attrs, int
defStyle) {
        super(context, attrs, defStyle);
        init();
    }

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

    public ListItemView(Context context) {
        super(context);
        init();
    }

    public void init(){
        linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        linePaint.setColor(Color.parseColor("#000000"));
    }
    public boolean isHeader() {
        return isHeader;
    }

    public void setHeader(boolean isHeader) {
        this.isHeader = isHeader;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if(isHeader){
            canvas.drawColor(Color.parseColor("#AAFFFF99"));
        }
        canvas.drawLine(0, 0, getMeasuredWidth(), 0,linePaint);
        canvas.drawLine(0, getMeasuredHeight(), getMeasuredWidth(),
getMeasuredHeight(),linePaint);
        canvas.drawLine(0,0, 0, getMeasuredHeight(),linePaint);
    }
}


++++++++++++++++ DataGrid.java ++++++++++++++++++++++++++++++

package qi.com.DataGrid;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;


public class DataGridActivity extends Activity {
        Context mContext;
    Book[] books = {new Book("Title","Author"),new Book("Clean
Code","Uncle Bob"),new Book("Face 2.0","Allen Cooper")};
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        setContentView(R.layout.main);
        ListView bookListView
=(ListView)findViewById(R.id.bookListView);

        /* ERROR IN THIS LINE : row can't be resolved  */
        LitemItemAdapter mcqListAdapter = new
LitemItemAdapter(this,R.layout.row,books);


        bookListView.setAdapter(mcqListAdapter);
    }
    class LitemItemAdapter extends ArrayAdapter<Book>{

        public LitemItemAdapter(Context context, int
textViewResourceId,
                Book[] objects) {
            super(context, textViewResourceId, objects);
        }
        public View getView(int position, View convertView, ViewGroup
parent) {
            View v = convertView;
            if (v == null) {

                LayoutInflater vi = (LayoutInflater)
mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

                 /* ERROR IN THIS LINE : row can't be resolved  */
                v = vi.inflate(R.layout.row, null);

            }
            Book item = books[position];
            if (item != null) {


                      /* ERROR IN THIS LINE : row can't be resolved
*/
                    ListItemView titleView = (ListItemView)
v.findViewById(R.id.title);
                    ListItemView authorView = (ListItemView)
v.findViewById(R.id.author);



                    if(position == 0){
                        titleView.setHeader(true);
                        authorView.setHeader(true);
                    }
                    if(titleView != null){
                        titleView.setText(item.getTitle());
                    }
                    if(authorView != null){
                        authorView.setText(item.getAuthor());
                    }
            }
            return v;
        }

    }


}


++++++++++++++++ end +++++++++++++++++++

i hopefull can help me to solve my problem..

thanx alot

:)

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to