當我運行這個程序時,它反覆說「無法解析符號setOnClickListener」。所以請幫我解決這個問題。無法解析android中的符號setOnClickListener
import android.support.v7.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set the content of the activity to use the activity_main.xml layout file
setContentView(R.layout.activity_main);
}
// Find the View that shows the numbers category
TextView numbers = (TextView) findViewById(R.id.numbers);
// Set a click listener on that View
numbers.setOnClickListener(new View.OnClickListener() {
// The code in this method will be executed when the numbers View is clicked on.
@Override
public void onClick(View view) {
Intent numbersIntent = new Intent(MainActivity.this, Numbers.class);
startActivity(numbersIntent);
}
}
}
移動你的代碼插件ide'onCreate()'。 – earthw0rmjim
是或實現'OnClickListener'和'numbers.setOnClickListener(this);' – Amg91