这是我的代码:
public class EnterActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.enter);
Button search = (Button) findViewById(R.id.search);
search.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String[] answers = {
"das",
"das",
"dsa"
};
EditText eproduct = (EditText) findViewById(R.id.product);
EditText efactory = (EditText) findViewById(R.id.factory);
GridView grid = (GridView) findViewById(R.id.grid);
String product = eproduct.getText().toString();
String factory = efactory.getText().toString();
FrenchList french = new FrenchList();
int frenchResult = french.getCosher(product, factory);
//error is here
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, answers);
}
});
}}
错误是:“构造函数ArrayAdapter(new View.OnClickListener(){},int,String [])未定义”
我做了一些关于类似问题的搜索,我很确定问题是我没有正确使用上下文,但根据我的理解,只要“this”出现在扩展活动的类中我应该是好的。 为什么会出现此错误?我该如何解决?
答案 0 :(得分:2)
this
引用View.OnClickListener
类,在此示例中是一个匿名内部类。您可以使用EnterActivity.this
。