我的GridView和GridView中的按鈕有問題。這個想法是,人點擊網格中每個「項目」內的按鈕,彈出一個對話框,其中包含與該網格相關的文本(其已經在textView中但可見性設置爲隱藏「)。GridView按鈕,只有其中一個工作
只有在GridView中的第一個按鈕正常工作,其他人只是閱讀的「角色」。
這裏是MyAdapter.java類
public class MyAdapter extends BaseAdapter {
Context context;
ArrayList<Players> playerList;
private static LayoutInflater inflater = null;
Button btnRoleReveal;
public MyAdapter(Context context, ArrayList<Players> playerList){
this.context = context;
this.playerList = playerList;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return playerList.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null)
convertView = inflater.inflate(layout_grid_item, null);
final Button button = (Button) convertView.findViewById(R.id.btnRoleReveal);
TextView idTextView = (TextView) convertView.findViewById(R.id.tv_player_id);
TextView nameTextView = (TextView) convertView.findViewById(R.id.tv_player_name);
final TextView roleTextView = (TextView) convertView.findViewById(R.id.tv_player_role);
final String role = roleTextView.getText().toString();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialog.Builder(context)
.setTitle("Test")
.setMessage(role)
.show();
}
});
Players p = new Players();
p = playerList.get(position);
idTextView.setText("ID: " + String.valueOf(p.getId()));
nameTextView.setText("Name: " + String.valueOf(p.getName()));
roleTextView.setText("Role: " + String.valueOf(p.getRole()));
return convertView;
}
}
我已閱讀,我可能需要以編程方式,但我添加按鈕我不知道如何解決這個問題。如果您需要查看任何附加代碼或者有任何建議,請聯繫我們放心讓我知道。
謝謝