【发布时间】:2015-05-16 20:21:08
【问题描述】:
我有一个 GridView 用于我正在填充字符串数组的 wordsearch 应用程序。但是我想从左下角填充它然后向上而不是默认的左上角向下填充。
我之前在这里问过一个问题,并被告知实现这一点的方法是编写一个我已经完成的自定义 ArrayAdapter,但是我对 Android 很陌生,不知道如何填充网格从适配器的左下角开始。
我还需要能够获取网格中被点击的项目的元素编号,类似于我现在正在做的:
position = wordsearchGrid.pointToPosition((int)X, (int)Y);
这是我迄今为止为自定义适配器编写的代码,它可以工作,但显然仍然从左上角填充:
public class GridAdapter extends ArrayAdapter
{
Context context;
Object[] items;
int resource;
LayoutInflater inflater;
public GridAdapter(Context context, int resource, Object[] items)
{
super(context, resource, items);
this.context = context;
this.resource = resource;
this.items = items;
inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount()
{
return items.length;
}
@Override
public Object getItem(int position)
{
return items[position];
}
@Override
public long getItemId(int position)
{
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
TextView cell;
int cellWidth = 40;
int cellHeight = 50;
if (convertView == null)
{
// If convertView is null then inflate the appropriate layout file
convertView = inflater.inflate(resource, null);
}
cell = (TextView) convertView.findViewById(R.id.gridCell);
cell.setText((CharSequence) items[position]);
// Set height and width constraints for the image view
cell.setLayoutParams(new LinearLayout.LayoutParams(cellWidth, cellHeight));
// Set Padding for images
cell.setPadding(1, 1, 1, 1);
return convertView;
}
}
谁能简要介绍一下我将如何填充网格以使左下角的单元格成为数组的第一个元素?
谢谢。
【问题讨论】:
标签: java android gridview android-arrayadapter