button1
Androidのトーストに少し問題があります:/がアクティブになるときに小さなトーストを作成したい
ここに私のコードがあります:
MainActivity.java
package com.andruiden.toast;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.*;
import android.widget.*;
import com.andruiden.toast.R;
public class MainActivity extends Activity {
//Klick Listener
class MeinClickListener implements OnClickListener{
public void onClick(View v){
String text = "Es wurde geklickt";
Toast t = Toast.makeText(v.getContext(), text, Toast.LENGTH_SHORT);
t.show();
}
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Button beim Hörer registrieren
MeinClickListener t = new MeinClickListener();
Button test = (Button) findViewById(R.id.button1);
test.setOnClickListener(t);
}
}
行test.setOnClickListener(t);
でエラーが発生します:
The method setOnClickListener(View.OnClickListener) in the type view is not applicable to the arguments
どういう意味ですか?
ここでコードを次のように変更できます。
test.setOnClickListener((android.view.View.OnClickListener) t);
しかし、Galaxy S2 で .apk を実行しても何も起こりません.. :/
下手な英語でごめんなさい xD