Answer the question
In order to leave comments, you need to log in
How to access nth item of GridView from adapter?
Good day to all :)
I created a GridView with the number of (large) buttons I needed. I need that by clicking on one of the buttons, I could change the parameters of the adjacent or any other button found by position - for example, make it unpressable (it sounds kind of crooked in Russian, but oh well). I process pressing directly inside the adapter (I don’t know how true this is, since I’m just starting to write for android). The adapter is custom, inherited from BaseAdapter. The getView method in my implementation now looks like this:
@Override
public View getView(final int position, final View convertView, final ViewGroup parent) {
View grid = convertView;
if(convertView == null ) {
LayoutInflater inflater = LayoutInflater.from(mContext);
grid = inflater.inflate(R.layout.item_battle_field, parent, false);
} else {
grid = convertView;
}
final ImageButton imageButton = grid.findViewById(R.id.item_battle_field);
imageButton.setImageResource(R.drawable.battle_field_color);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(mContext, String.valueOf(position), Toast.LENGTH_SHORT).show();
}
});
return grid;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question