Buttons - Working on Intent

  • Replies:3
Carnagemeister
  • Forum posts: 2

Dec 4, 2016, 3:25:07 PM via Website

Hello, I'm creating a button that will start a new activity but it gives me an error Cannot Resolve symbol OnClickListener

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button b1 = (Button) findViewById(R.id.viewb);
    b1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, View.class));
        }
    });

    Button b2 = (Button) findViewById(R.id.adminb);
    b2.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, Admin.class));
        }
    });
}
}

I'm using the correct syntax but it still gives me errors

Reply
jack McGeor
  • Forum posts: 6

Dec 6, 2016, 11:04:34 AM via Website

Hello !
Use this in your button syntax :

b1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(), View.class);
startActivity(i);

    }
});

Reply
jack McGeor
  • Forum posts: 6

Dec 6, 2016, 11:08:32 AM via Website

Download : Master Android App From Play Store ;

You can See Lessons about it on Best Android app development resource :
Download the App : "Master Android" & See the full tutorials about :
-This App Have 3 Main Parts :
1- Android Lessons
2- Coding Challenges
3- Ask Developers

In this app, you will discover the power of Android app development, and obtain skills to dramatically increase your career prospects as a software developer.

  • OUR APP RECEIVES LESSONS & CHALLENGES FROM ONLINE & REALTIME DATABASES !

-Develop apps for the very latest version of Android 7 Nougat that also work on older Android devices running older versions of the Android operating system

Become skilled faster with the app combination of Infographics , Pictures, Videos & Source Codes .. All designed to teach you everything you need to know.

Android Lessons ---You will learn :

  • How Android App Works & Its Components (App Components)
  • Firebase, SQLite, MySql, Shared Preferences (Data Storage)
  • Camera, Playback, Audio, Videos... (Media & Camera)
  • JSON, Web Servers, XML Parsing & Data Fetching. (Web & Remote Access)
  • WiFi, Bluetooth, NFC, USB (Connectivity)
  • Maps, Markers, Tracking, GeoCoding, Locations ... (Google Maps)
  • Master Material Design & UI (User Interface)
  • Localization, Layouts, Strings, Styles, Menu.. (App Resources)

-Develop apps for the very latest version of Android 7 Nougat that also work on older Android devices running older versions of the Android operating system

-Download, install and configure the necessary (free) software
-Build a range of apps demonstrating key aspects of the Android framework
-Test your apps on emulators or a real Android phone or tablet
-Ensure your apps work with current and older Android versions on phones and tablets
-Use Android studio 2.2, the newest version of Googles premier Android tool
-Learn how to use databases, web services, and even get your apps to speak!
-Expand your knowledge with the challenges in the course that are designed to really help you become a better programmer (we show and explain the solutions as well).
-Get a head start on other developers still using obsolete tools and versions of Android

Reply
@KINGMOWW08
  • Forum posts: 5

Dec 7, 2016, 1:11:35 PM via Website

Need fun!

Reply