简体   繁体   中英

Android studio new activity

I am trying to start a new activity in android studio when I click on the image . I looked here for answers and on google but I guess i'm doing something wrong .

Userareaactivity.java :

final ImageView magnifying = (ImageView) findViewById(R.id.magnifying);

magnifying.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent UserSearchIntent = new Intent(UserAreaActivity.this, UserSearch.class);
            UserAreaActivity.this.startActivity(UserSearchIntent);
}
});

activity_user_area.xml :

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/magnifying"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:src="@drawable/magnifying"
    android:clickable="true" />

androidmanifest.xml :

   <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".LoginActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".RegisterActivity" />
    <activity android:name=".UserAreaActivity" />
    <activity android:name=".UserSearch"></activity>
  </application>

What it sounds like you're looking for is the Android equivalent of hyperlinking, yes?

Try this.

    imageViewName.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(getApplicationContext(), YourNewActivity.class));
        }
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM