-1

i created a tab view with three pages in one of the pages i added a list view in that view i added a text view which should move to another activity when clicked but when i create the intent i get a n error and the id of the onClick is never used the error java.lang.IllegalStateException: Could not find a method (View)


this is the code:

package com.halbader.runescape;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


    package com.halbader.runescape;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


public class QuestsPage extends Fragment {


public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.questspage, container, false);
    return rootView;


}



public void drSlayerQ(View view){
    Intent qIntent = new Intent(this, DragonSlayerQuest.class);
    QuestsPage.this.startActivity(qIntent);
}



}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • 1
    Possible duplicate of [How do I pass data between Activities in Android application?](http://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android-application) – Phil3992 Apr 07 '17 at 15:48

2 Answers2

0

Try this :

First bind a proper ID in your Java to your xml element. Then set an OnClickListener and in that, call the function (No need to pass the parameter).

public void drSlayerQ(View view){
    Intent qIntent = new Intent(getContext(), DragonSlayerQuest.class);
    getActivity().startActivity(qIntent);
}
Basu
  • 763
  • 8
  • 27
  • TextView moveToQuest1; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.questspage, container, false); return rootView; moveToQuest1 = (TextView) findViewById(R.id.quest1); moveToQuest1.setOnClickListener(new View.OnClickListener(){ public void onClick(View view){ Intent qIntent = new Intent(QuestsPage.this, DragonSlayerQuest.class); QuestsPage.this.startActivity(qIntent); } }); – Hussain Albader Apr 07 '17 at 17:49
0

Try this as you are moving from fragment to activity :

private void moveToNewActivity() {
    Intent i = new Intent(getActivity(), DetailActivity.class);
    startActivity(i);
    ((Activity) getActivity()).overridePendingTransition(0,0);

}

Here overridePendingTransition(0,0); means no Animation in transition.

Aniket Jadhav
  • 166
  • 11