从左下角填充 gridview
populate gridview from bottom left
我正在寻找一种方法来从左下角穿过并向上填充 gridview,而不是从左上角穿过并向下填充 gridview,但仍然能够使用 pointToPosition(x, y) 来获取数组中的正确元素(因此左下角为 0)。
我不完全确定这是否可能,但我想一定是,但是我想不出任何方法来做到这一点而不会破坏正确查找数组索引的能力。任何帮助将不胜感激。
这里是获取用于填充网格的字符串数组的代码:
int num = 0;
//populates a standard array from the grid in the JSONObject
for (int vertical = 0; vertical < puzzleArray.size(); vertical++) //rows
{
for (int horizontal = 0; horizontal < puzzleArray.get(0).length(); horizontal++) //columns
{
//adds each letter of each row stored in puzzleArray to puzzleInputArray
puzzleInputArray[num] = puzzleArray.get(vertical).charAt(horizontal) + "";
num++;
}
}
puzzleArray 由 9 个字母组成的 9 个字符串组成,然后用上面的代码将它们分成一个单独的数组。
我用标准的 ArrayAdapter 填充 GridView:
//fill GridView with the puzzle input array from the puzzle class
ArrayAdapter<String> gridAdapter = new ArrayAdapter<String>(c, R.layout.cell_layout, todaysPuzzle.puzzleInputArray);
wordsearchGrid.setAdapter(gridAdapter);
而且我需要能够在网格上调用等效项:
case MotionEvent.ACTION_DOWN:
downX = event.getX();
downY = event.getY();
startPosition = wordsearchGrid.pointToPosition((int)downX, (int)downY);
letterDown = (String) wordsearchGrid.getItemAtPosition(startPosition);
谢谢。
要解决您的问题,您只需使用更先进的技术来创建您的适配器。
用一行代码编写适配器很棒,但是要获得更加自定义的将数组适配到 gridView 的体验,您必须自己编写一个 BaseAdapter。
从那里开始,它会很简单,例如你可以有两个数组作为它的成员变量,一个存储"real"个索引,一个存储"displaying"个索引。
希望对你有所帮助 :) !
我正在寻找一种方法来从左下角穿过并向上填充 gridview,而不是从左上角穿过并向下填充 gridview,但仍然能够使用 pointToPosition(x, y) 来获取数组中的正确元素(因此左下角为 0)。
我不完全确定这是否可能,但我想一定是,但是我想不出任何方法来做到这一点而不会破坏正确查找数组索引的能力。任何帮助将不胜感激。
这里是获取用于填充网格的字符串数组的代码:
int num = 0;
//populates a standard array from the grid in the JSONObject
for (int vertical = 0; vertical < puzzleArray.size(); vertical++) //rows
{
for (int horizontal = 0; horizontal < puzzleArray.get(0).length(); horizontal++) //columns
{
//adds each letter of each row stored in puzzleArray to puzzleInputArray
puzzleInputArray[num] = puzzleArray.get(vertical).charAt(horizontal) + "";
num++;
}
}
puzzleArray 由 9 个字母组成的 9 个字符串组成,然后用上面的代码将它们分成一个单独的数组。
我用标准的 ArrayAdapter 填充 GridView:
//fill GridView with the puzzle input array from the puzzle class
ArrayAdapter<String> gridAdapter = new ArrayAdapter<String>(c, R.layout.cell_layout, todaysPuzzle.puzzleInputArray);
wordsearchGrid.setAdapter(gridAdapter);
而且我需要能够在网格上调用等效项:
case MotionEvent.ACTION_DOWN:
downX = event.getX();
downY = event.getY();
startPosition = wordsearchGrid.pointToPosition((int)downX, (int)downY);
letterDown = (String) wordsearchGrid.getItemAtPosition(startPosition);
谢谢。
要解决您的问题,您只需使用更先进的技术来创建您的适配器。
用一行代码编写适配器很棒,但是要获得更加自定义的将数组适配到 gridView 的体验,您必须自己编写一个 BaseAdapter。
从那里开始,它会很简单,例如你可以有两个数组作为它的成员变量,一个存储"real"个索引,一个存储"displaying"个索引。
希望对你有所帮助 :) !