我在第一页上工作了,但第二页上有youtube教程,但是似乎无法按照我想要的方式工作。页面的处理方式有所不同。
private void setSingleEvent(GridLayout mainGrid) {
//Loop all child item of Main Grid
for (int i = 0; i < mainGrid.getChildCount(); i++) {
//You can see , all child item is CardView , so we just cast object to CardView
CardView cardView = (CardView) mainGrid.getChildAt(i);
final int finalI = i;
cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (finalI == 0) // open page 1
{
Intent intent = new Intent (MainActivity.this, StarterVapes.class);
startActivity(intent);
}
else if (finalI == 1) // open page 2
{
Intent intent = new Intent (MainActivity.this, UpgradeVapes.class);
startActivity(intent);
}
@Override
public void onBindViewHolder(final ViewHolder viewHolder, final int i) {
viewHolder.imgView.setImageResource(imagesList.get(i));
viewHolder.txtTitle.setText(titleList.get(i));
final int finalI = i;
viewHolder.parentLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (finalI == 0) // open page 1
{
Intent intent = new Intent (context, AboutUS.class);
context.startActivity(intent);
}
else if (finalI == 1) // open page 2
{
Intent intent = new Intent (context.this, AboutUS.class);
context.startActivity(intent);
}
// Intent intent = new Intent(context, DetailActivity.class);
// intent.putExtra("title", titleList.get(i));
// context.startActivity(intent);
}
});
我希望它是您单击进入页面的第一个图块,然后单击进入另一个页面的第二个图块,依此类推。
答案 0 :(得分:0)
abs(x - 8)
Got it working