Kais Kotamy
Kais Kotamy

Reputation: 15

Move to another activity

I have a ListView which has 2 items.
Each one is a ListView.
I just want to move to another Activity when I click an item.

I have this bit of code

public void onBindViewHolder(HomeHolder holder, int position) {  
     holder.recyclerView.setAdapter(new InHomeAdapter(inflater)); 
     holder.recyclerView.setLayoutManager(new LinearLayoutManager(context, 
     LinearLayoutManager.HORIZONTAL, false)); 
     holder.recyclerView.addOnItemTouchListener(new 
     InHomeAdapter.InHomeListener(context, new InHomeAdapter.ClickListener() {         
          @Override
          public void onClick(InHomeAdapter.InHomeHolder holder, View view, int position) { 
               Intent i = new Intent(this,movie_Detailes.class); 
          }
     }); 
}

I get a red line under "movie_detailes.class".
How can I do that?

Upvotes: 0

Views: 109

Answers (3)

Deena Nath
Deena Nath

Reputation: 301

try these code

//Create constructor of your Adapter class 
 Context context;
 public YourAdapterClass(Context context){
   this.context = context;
 }

then

public void onBindViewHolder(HomeHolder holder, int position) {  
 holder.recyclerView.setAdapter(new InHomeAdapter(inflater)); 
 holder.recyclerView.setLayoutManager(new LinearLayoutManager(context, 
 LinearLayoutManager.HORIZONTAL, false)); 
 holder.recyclerView.addOnItemTouchListener(new 
 InHomeAdapter.InHomeListener(context, new InHomeAdapter.ClickListener() {         
      @Override
      public void onClick(InHomeAdapter.InHomeHolder holder, View view, int position) { 
           Intent intent = new Intent(context,movie_Detailes.class); 
           startActivity(intent)
      }
 }); 

}

Upvotes: 0

Harshal Pathak
Harshal Pathak

Reputation: 787

    //in adapter constructer
 Context context;
 public CustomAdapter(Context context){
   this.context = context;
 }
 public void onBindViewHolder(HomeHolder holder, int position) {
        holder.recyclerView.setAdapter(new InHomeAdapter(inflater));
        holder.recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
        holder.recyclerView.addOnItemTouchListener(new InHomeAdapter.InHomeListener(context, new InHomeAdapter.ClickListener() {
            @Override
            public void onClick(InHomeAdapter.InHomeHolder holder, View view, int position) {
                Intent i = new Intent(context, movie_Detailes.class);
                context.startActivity(i);
            }
        }));
    }  

Upvotes: 0

Bhupat Bheda
Bhupat Bheda

Reputation: 1978

try this

  //in adapter constructer
     Context context;
     public CustomAdapter(Context context){
       this.context = context;
     }
     public void onBindViewHolder(HomeHolder holder, int position) {
            holder.recyclerView.setAdapter(new InHomeAdapter(inflater));
            holder.recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
            holder.recyclerView.addOnItemTouchListener(new InHomeAdapter.InHomeListener(context, new InHomeAdapter.ClickListener() {
                @Override
                public void onClick(InHomeAdapter.InHomeHolder holder, View view, int position) {
                    Intent i = new Intent(context, movie_Detailes.class);
                }
            }));
        }  

Upvotes: 1

Related Questions