美好的一天我目前正致力于一个看起来像财富之轮的项目。我有这个适配器,我想知道是否有可能有一个计数器将数据发送到另一个类,如果它在其他最底层请帮助谢谢
package com.forteza.answerme.adapter;
公共类GridViewSuggestAdapter扩展了BaseAdapter {
private List<String> suggestSource;
private Context context;
private Level2 level2;
public GridViewSuggestAdapter(List<String> suggestSource, Context context, Level2 level2) {
this.suggestSource = suggestSource;
this.context = context;
this.level2 = level2;
}
@Override
public int getCount() {
return suggestSource.size();
}
@Override
public Object getItem(int position) {
return suggestSource.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
Button button;
if(convertView == null)
{
if(suggestSource.get(position).equals("null"))
{
button = new Button(context);
button.setLayoutParams(new GridView.LayoutParams(85,85));
button.setPadding(8,8,8,8);
button.setBackgroundColor(Color.DKGRAY);
}
else
{
button = new Button(context);
button.setLayoutParams(new GridView.LayoutParams(85,85));
button.setPadding(8,8,8,8);
button.setBackgroundColor(Color.DKGRAY);
button.setTextColor(Color.YELLOW);
button.setText(suggestSource.get(position));
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int error=0;
//If correct answer contains character user selected
if(String.valueOf(level2.answer).contains(suggestSource.get(position)))
{
char compare = suggestSource.get(position).charAt(0); // Get char
for(int i =0;i<level2.answer.length;i++)
{
if(compare == level2.answer[i])
Common.user_submit_answer[i] = compare;
}
//Update UI
GridViewAnswerAdapter answerAdapter = new GridViewAnswerAdapter(Common.user_submit_answer,context);
level2.gridViewAnswer.setAdapter(answerAdapter);
answerAdapter.notifyDataSetChanged();
//Remove from suggest source
level2.suggestSource.set(position,"null");
level2.suggestAdapter = new GridViewSuggestAdapter(level2.suggestSource,context,level2);
level2.gridViewSuggest.setAdapter(level2.suggestAdapter);
level2.suggestAdapter.notifyDataSetChanged();
}
else // else
{
//Remove from suggest source
level2.suggestSource.set(position,"null");
level2.suggestAdapter = new GridViewSuggestAdapter(level2.suggestSource,context,level2);
level2.gridViewSuggest.setAdapter(level2.suggestAdapter);
level2.suggestAdapter.notifyDataSetChanged();
}
}
});
}
}
else
button = (Button)convertView;
return button;
}
}
答案 0 :(得分:0)
在该适配器上创建一个接口,并在满足条件时触发该侦听器。在您的其他活动上实施该界面,并在您的活动中的已实施方法中执行某些操作。