单击Recolycer视图中的项目时,我希望它打开一个新的活动。这是主要活动
package com.example.myclassroom;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.Intent;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.example.myclassroom.helperclass.HomeAdapter.ItemClickListener;
//import com.example.myclassroom.helperclass.HomeAdapter.OnUGListener;
import com.example.myclassroom.helperclass.HomeAdapter.PGadapter;
import com.example.myclassroom.helperclass.HomeAdapter.PGhelperclass;
import com.example.myclassroom.helperclass.HomeAdapter.UGadapter;
import com.example.myclassroom.helperclass.HomeAdapter.UGhelperclass;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.navigation.NavigationView;
import com.google.firebase.auth.FirebaseAuth;
import java.util.ArrayList;
import java.util.List;
public class firstpage extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, BottomNavigationView.OnNavigationItemSelectedListener {
//navigation
static final float END_SCALE = 0.7f;
private DrawerLayout drawer;
private NavigationView navigation;
public List<UGhelperclass> uglocation;
LinearLayout contentView;
//cards
RecyclerView ugrecycler, pgrecycler;
RecyclerView.Adapter adapter;
ImageView menuIcon;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_firstpage);
//hooks
ugrecycler = findViewById(R.id.ug_recycler);
pgrecycler = findViewById(R.id.pg_recycler);
contentView = findViewById(R.id.content_id);
//Menu hooks
navigation = findViewById(R.id.nav_view);
drawer = findViewById(R.id.drawer_layout);
menuIcon = findViewById(R.id.menu_icon);
ugrecycler();
pgrecycler();
navigationDrawer();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.search, menu);
MenuItem.OnActionExpandListener onActionExpandListener = new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem menuItem) {
return false;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem menuItem) {
return false;
}
};
return true;
}
private void navigationDrawer() {
//navigation drawer
navigation.bringToFront();
navigation.setNavigationItemSelectedListener(this);
navigation.setCheckedItem(R.id.nav_home);
menuIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (drawer.isDrawerVisible(GravityCompat.START))
drawer.closeDrawer(GravityCompat.START);
else drawer.openDrawer(GravityCompat.START);
}
});
animateNavigationDrawer();
}
private void animateNavigationDrawer() {
drawer.setScrimColor(getResources().getColor(R.color.bg));
drawer.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
//scale the view based on current slide effect
final float diffScaledOffset = slideOffset * (1 - END_SCALE);
final float offSetScale = 1 - diffScaledOffset;
contentView.setScaleX(offSetScale);
contentView.setScaleY(offSetScale);
//transilate the view
final float xoffset = drawerView.getWidth() * slideOffset;
final float xoffsetDiff = contentView.getWidth() * diffScaledOffset / 2;
final float xTranslation = xoffset - xoffsetDiff;
contentView.setTranslationX(xTranslation);
}
});
}
@Override
public void onBackPressed() {
if (drawer.isDrawerVisible(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.nav_ebook:
Intent intent = new Intent(firstpage.this, fragment_ebooks.class);
startActivity(intent);
finish();
break;
case R.id.nav_logout:
FirebaseAuth.getInstance().signOut();
intent = new Intent(firstpage.this, loginpage.class);
startActivity(intent);
finish();
case R.id.nav_share:
break;
}
drawer.closeDrawer(GravityCompat.START);
return true;
}
private void pgrecycler() {
pgrecycler.setHasFixedSize(true);
pgrecycler.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
ArrayList<PGhelperclass> pglocation = new ArrayList<>();
pglocation.add(new PGhelperclass(R.drawable.computer_main_screen, "Computer Science", "Notes for Bsc and BCA"));
pglocation.add(new PGhelperclass(R.drawable.microbiology, "Microbiology", "Notes for micro"));
pglocation.add(new PGhelperclass(R.drawable.chemistry, "Chemistry", "Notes for chemistry"));
PGadapter adapter = new PGadapter(pglocation);
pgrecycler.setAdapter(adapter);
}
private void ugrecycler() {
ugrecycler.setHasFixedSize(true);
ugrecycler.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
final ArrayList<UGhelperclass> uglocation = new ArrayList<>();
uglocation.add(
new UGhelperclass(
1,
R.drawable.computer_main_screen,
"Nandhini",
"https://firebasestorage.googleapis.com/v0/b/my-classroom-50f12.appspot.com/o/11.pdf?alt=media&token=48bb603d-b7b9-4588-9539-33381077afd2",
6000
));
UGadapter adapter = new UGadapter(this, uglocation);
ugrecycler.setAdapter(adapter);
}
}
这是适配器
package com.example.myclassroom.helperclass.HomeAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.myclassroom.R;
import com.google.firebase.database.core.Context;
import java.util.ArrayList;
public class PGadapter extends RecyclerView.Adapter<PGadapter.PGviewholder> {
//1
private final ArrayList<PGhelperclass> pglocation;
//2
public PGadapter(ArrayList<PGhelperclass> pglocation) {
this.pglocation = pglocation;
}
@NonNull
@Override
public PGviewholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.pg_card_design,parent,false);
PGviewholder pgviewholder = new PGviewholder(view);
return pgviewholder;
}
@Override
public void onBindViewHolder(@NonNull PGadapter.PGviewholder holder, int position) {
PGhelperclass pghelperclass = pglocation.get(position);
holder.image.setImageResource(pghelperclass.getImage());
holder.title.setText(pghelperclass.getTitle());
holder.desc.setText(pghelperclass.getDescription());
}
@Override
public int getItemCount() {
return pglocation.size();
}
//3
public static class PGviewholder extends RecyclerView.ViewHolder {
ImageView image;
TextView title,desc;
public PGviewholder(@NonNull View itemView) {
super(itemView);
//hooks
image = itemView.findViewById(R.id.pg_img);
title = itemView.findViewById(R.id.pg_course_title);
desc = itemView.findViewById(R.id.pg_desc);
}
}
}
package com.example.myclassroom.helperclass.HomeAdapter;
public class PGhelperclass {
int image;
String title, description;
public PGhelperclass(int image, String title, String description) {
this.image = image;
this.title = title;
this.description = description;
}
public int getImage() {
return image;
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
}
...................................................
在OnBindViewWholder类中,
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(position==1){
Intent intent = new Intent(itemView.getContext(), SecondActivity.class);
}else if(position==2){
Intent intent = new Intent(itemView.getContext(), SomeOtherActivity.class);
}
itemView.getContext().startActivity(intent);
}
});
@覆盖公共void onBindViewHolder(@NonNull ViewHolder holder,int位置){ 在onBindViewHolder中,我想调用另一个活动,但每次调用侦听器时,都会打开同一个活动。注意:Recycler是通过另一个cardview活动从MYSQL获取值的
购物清单活动: }
我已经完成了导航,现在进入第一个片段。在第一个片段中有两个按钮,我需要通过按下这些按钮来切换到一个新的活动。我不明白如何正确地实施它。我犯了一个错误。 代码,eror
Activity1还实现了我正在调用的Activity1的PaymentResponseListener和onResume PaymentResponse.ValidatePaymentResponse(getIntent(),Activity1.this);//此函数来自他们的sdk,并且是只读的。 现在,当Activity1启动ATH Movil应用程序并获得响应时。它再次创建Activity
我在一个活动中有一个列表视图,在自定义适配器中有一个信息图标。当用户点击该信息按钮时,下一个活动将打开,当用户点击更新按钮时,在下一个活动中标记出勤率后,第二个活动应该完成,第一个活动列表视图应该更新。 我成功地做了什么:我已经成功地标记了出席情况并更改了listview的颜色,但我在关闭第二个活动并重新启动第一个活动后这样做了。通过这种方式,由于再次开始活动,listview会得到更新。 我无法