2016-05-25 1 views
0

を解決することはできません私はあなたがそこに書いた機能元findViewById(int)に意図していないと仮定すると、意図はメソッド「findViewById」

package com.smartcodeone.newapp1; 

import android.content.Intent; 
import android.os.Bundle; 
import android.support.v7.app.ActionBarActivity; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.widget.Button; 

public class MainActivity extends ActionBarActivity { 

    public static final String STRING_VAR = "com.smartcodeone.newapp1.HELLO_WORLD"; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     Button btnMsg = (Button) findViewById(R.id.btnMsg); 


     btnMsg.setOnClickListener(new View.OnClickListener(){ 

      //when user click's this function will be called 
      public void onClick(View v){ 
       Intent intentvar = new Intent(getApplicationContext(),Main2Activity.class); 
       intentvar.putExtra(STRING_VAR,"Hello World"); //this is used to pass data to next intent 
       startActivity(intentvar); 
      } 
     }); 


    } 

    private int findViewId(int btnMsg) { 
      return 0; 

    } 


    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.menu_main, menu); 
     return true; 



    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 

     //noinspection SimplifiableIfStatement 
     if (id == R.id.action_settings) { 
      return true; 
     } 

     return super.onOptionsItemSelected(item); 
    } 

    @Override 
    public android.support.v4.app.FragmentManager getSupportFragmentManager() { 
     return null; 
    } 
} 
+0

問題をより詳しく説明し、コードの関連部分のみを投稿してください。 – sschale

+0

あなた自身の 'findViewById'を使ってみようとしていますか? – Amirag

答えて

-1

を介して2つの活動に参加しています:
ではなく、活動から延びる試しを。
これは、使用しなかった無駄な機能を削除し、android.app.Activityをインポートする必要があることを意味します。

さらに、android.support.v7.*パッケージを使用しないでください。
私の小さな経験から、あなたはそれで何をやっているのか分からない限り、トラブルを引き起こすだけです。

+1

あなたの提案がどのように問題を解決するかわかりません。 ActionBarActivityにはfindViewById()もあります。 – Egor

+0

どのような提案が問題を解決するかはわかりません。さらに、サポートv7のバージョンでは、Androidバージョン間でより一貫性のある体験を作成できます。 – cyroxis

2

Androidスタジオと関連があるかもしれません。プロジェクトを掃除して再構築してみてください。それがうまくいかない場合は、[ファイル] - > [キャッシュを無効にする/再起動...]に移動します。

これらの問題も時々発生します。そのことが分かれば教えてください。私はあなたのコードを試して、それは正常に動作します。 findViewById(int button)常に0

独自の代わりに活動方法を使用して返す:

this.findViewById(int resourceId)

幸運

0

問題は、名前のメソッドを定義していることのようです!

0

あなた自身のfindviewbyid()を実装しているようです。あなたがそうするつもりなら、私は知らない。

はActionBarActivityのfindviewbyidは、レイアウトファイルからボタンを解決する必要があります

private int findviewbyid(int btnMsg) { 
} 

を削除してください。

関連する問題