我正在尝试为 Eclipse 中的图像按钮设置 onclicklistener。单击后,应用程序应引导至默认联系人应用程序。这是我拥有的代码,但我在“}”括号中出现错误,我似乎无法弄清楚问题所在。任何人都可以帮忙吗?
public class First extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);
addButtonListener();
}
private void addButtonListener() {
// TODO Auto-generated method stub
//finding your image button
ImageButton btn1 = (ImageButton) findViewById(R.id.imageButton2);
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, 1);
}); //!!!!THE ERROR APPEARS UNDER THE } BRACKET ON THIS LINE!!!
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
//Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.first, menu);
return true;
}
}