「setOnClickListener」の下に赤い線が表示されると、「setOnClickListenerを解決できません」というポップアップメッセージが表示され、「@Override」に「注釈はここでは許可されていません」と表示されます。 「vを見る」のvも私にエラーを与えています。私はどこでうんざりしたのですか? onClickListener
を設定するための注文方法などonCreate
内にコードを移動する必要私はエラーが発生した私のsetOnClickListenerですか?
答えて
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class EmailReceiptActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_email_receipt);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_options_menu, menu);
menu.findItem(R.menu.main_options_menu).setIntent(
new Intent(EmailReceiptActivity.this, LaunchActivity.class));
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
//use the id of the item from main_options_menu
if (id == R.id.logoff_menu_item) {
super.onOptionsItemSelected(item);
startActivity(item.getIntent());
}
return true;
}
Button btn_send = (Button)findViewById(R.id.send_receipt_button);
btn_send.setOnClickListener(new View.OnClickListener(){
@Override
//Use the name of the function you assigned to the xml design of the button
public void onClick(View v){
//Use the name of this class, and the name class where you want to be taken when the button is clicked.
startActivity (new Intent(EmailReceiptActivity.this, SuccessActivity.class));
}
}
}。関数本体の外でそのようなコードを実行することはできません。また、それは... onCreate
の外に、よりグローバルスコープを使用してButton
を宣言し、そうしようとするよりも有用である
public Button btn_send;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_email_receipt);
btn_send = (Button)findViewById(R.id.send_receipt_button);
btn_send.setOnClickListener(new View.OnClickListener(){
@Override
//Use the name of the function you assigned to the xml design of the button
public void onClick(View v){
//Use the name of this class, and the name class where you want to be taken when the button is clicked.
startActivity (new Intent(EmailReceiptActivity.this, SuccessActivity.class));
}
}
プライベートボタンsend_receipt_button。
public class GameOver extends AppCompatActivity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_email_receipt);
Button btn_send = (ImageButton) findViewById(R.id.send_receipt_button);
btn_send.setOnClickListener(this);
}
public void onClick (View v){
switch (v.getId()) {
case R.id.send_receipt_button:
startActivity (new Intent(EmailReceiptActivity.this, SuccessActivity.class));
break;
}
}
この回答は元の内容と同じように見えますが、ここで私が少し答えを出したことを知っておくべきです(http://stackoverflow.com/questions/39429490/pass-image-array-from-view-did-load -to-tableview-cell?noredirect = 1#comment66182594_39429490)これを削除することは、ここからの帰属なしにコピーされているため、正しいことでした。http://stackoverflow.com/a/25081954/294949これは剽窃とみなされ、ここでは非常に眉をひそめており、(見て分かるように)発見するのは簡単です。 – danh
これは私のアプリケーションで使用している私のオリジナルコードです。そして、存在する答えは盗用を助け、欺くことではなく、盗用は1つのブログやサービスwikiに投稿されるものではありません。 –
あなたの動機が他の人を助けることであると確信しています。誰か他の人の答えを示す正しい方法は、*リンク*することです。読者がその一部をコピーする方が意味がある場合は、ソースを引用してください。 – danh
あなたがそのように外にあなたのOnClickListener
を入れたい場合は、それは次のようにする必要があります:
OnClickListener sendListener = new View.OnClickListener(){
@Override
//Use the name of the function you assigned to the xml design of the button
public void onClick(View v){
//Use the name of this class, and the name class where you want to be taken when the button is clicked.
startActivity (new Intent(EmailReceiptActivity.this, SuccessActivity.class));
}
};
、あなたはonCreate
Button btn_send;
protected void onCreate(Bundle savedInstanceState) {
...
btn_send.setOnClickListener(sendListener);
}
のような領域にそれを設定しますが、理想的findViewById
とOnClickListener
の両方をonCreate
Button btn_send;
protected void onCreate(Bundle savedInstanceState) {
...
btn_send = (Button)findViewById(R.id.send_receipt_button);
btn_send.setOnClickListener(new View.OnClickListener(){
@Override
//Use the name of the function you assigned to the xml design of the button
public void onClick(View v){
//Use the name of this class, and the name class where you want to be taken when the button is clicked.
startActivity (new Intent(EmailReceiptActivity.this, SuccessActivity.class));
}
}
- 1. エラー:ドキュメントタイプは、要素 "div要素" 私は私のコードでエラーが発生した
- 2. PHP-HTML-ORACLE私はスクリプトでエラーが発生しました
- 3. 私はjava(Netbeans)でエラーが発生しました。
- 4. エラーが発生しましたが、私はそれが
- 5. 私のツールでMISRAエラーが発生したのはなぜですか?
- 6. 私はアンドロイドアプリの開発に新たなんだと、次のエラーが発生した保つ私はエラー
- 7. mysqli_num_rows()私はこのエラーが発生したパラメータ1が
- 8. res.should.have.status私にエラーが発生します
- 9. 私の最初のスプリングコードでエラーが発生しました
- 10. 私のAndroidコードのカーソルレベルでエラーが発生しました
- 11. 私のジャーナルサイトでXSS(クロスサイトスクリプティング)エラーが発生しました
- 12. 私のビューとサブビューでエラーが発生しました
- 13. Retrofit 2:私のGETリクエストでエラーが発生しました
- 14. 私は私のプロジェクトで問題が発生しました2.3
- 15. 私はこのエラーが発生しています。NSURLErrorDomainエラー-999
- 16. 私のアプリケーションでFacebookからエラーが発生しています
- 17. Laravelのアクセスは、私は私のlaravelアプリケーションでエラーが発生し、次の取得
- 18. ASP.NETコアで私にエラーが発生した模擬ロガー
- 19. 私のプロジェクトにエラーが発生しました
- 20. 私の質問にエラーが発生しました
- 21. RUBYは、私は現在、このエラーが発生します= 1
- 22. 私のRestAPIリクエストを実行している間、私はヘッダが必要ですエラーが発生しました
- 23. 私のコードでいくつかの論理エラーが発生しました
- 24. 私はこのエラーが発生します: "glibcが検出されました"
- 25. エラー、私はしばらくの間、私をブロックしたsymfony3の下で問題が発生した
- 26. 私は、whileループと私のコードで構文エラーが発生しているファイル
- 27. 私は単純なspring mvcサービスのテストでエラーが発生しました
- 28. フレームワーク私に直接エラーが発生しました。
- 29. 私は未定義のwp()エラーが発生しています
- 30. 私はこのエラーが発生します:com.android.internal.os.ZygoteInit $ MethodAndArgsCaller
これで解決しました。どうもありがとうございます! – agentmg123