我想爲eclipse中的imagebutton設置onclicklistener。點擊後,應用程序應該導致默認的聯繫人應用程序。這是我有的代碼,但我得到一個「}」括號錯誤,我似乎無法弄清楚什麼是問題。誰能幫忙?設置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;
}
}
你OPE ned {twicw但只關閉一次。 – LeeNeverGup