PDA

View Full Version : مشکل عجیب در کلاس baseAdapter



Navidshad
چهارشنبه 03 دی 1393, 12:47 عصر
سلام دوستان من میخوام یه جدول کلمات درست کنم با یک گرید ویو، حالا تو قسمت اول به مشکل خوردم.
تو کد زیر میخوام از طریق یک adapter که یک کلاس جدا داره محتوای گرید رو inflate کنم، اول امدم یک آرای length برای تعداد خانه های جدول ایجاد کردم، سپس یک آرای post_word برای خانه های سوالی ساختم. یک int هم برای شمارش آرایه post_word به نام counter ساختم.
سپس در تابع getView امدم عملیات inflating رو اجرا کردم، آما کد با counter مشکل داره و پیغام خطا میده



package com.example.crossword;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import android.widget.TextView;

public class CrossWord_Adapter extends BaseAdapter implements ListAdapter {

LayoutInflater inflater;
public int length = 9;
public int[] pos_word = {0,3,4,5,6};
public int counter = 0;

public CrossWord_Adapter(Context context) //difination -------|
{
inflater = LayoutInflater.from(context);
}

@Override
public int getCount() {
// TODO Auto-generated method stub
return length;
}

@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}

@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

holder layoutHolder;

if(position == pos_word[counter])
{
convertView = inflater.inflate(R.layout.layout_word, null);
layoutHolder = new holder();
layoutHolder.word = (TextView) convertView.findViewById(R.id.text_word);
convertView.setTag(layoutHolder);
if(counter < length)
{
counter++;
}
}
else
{
convertView = inflater.inflate(R.layout.layout_hashur, null);
}

return convertView;
}

class holder
{
TextView word;
}

}