0% found this document useful (0 votes)
17 views8 pages

New Text Document

The document contains code for an Android activity layout and class. The activity layout includes elements like a toolbar, text views, image views, card views, and recycler view to display campus opportunities. The activity class configures the recycler view and handles navigation drawer functionality.

Uploaded by

Pratham Rai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views8 pages

New Text Document

The document contains code for an Android activity layout and class. The activity layout includes elements like a toolbar, text views, image views, card views, and recycler view to display campus opportunities. The activity class configures the recycler view and handles navigation drawer functionality.

Uploaded by

Pratham Rai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

// this is my Activity_Main.

xml File code

<?xml version="1.0" encoding="utf-8"?>


<androidx.drawerlayout.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawerlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
tools:context=".MainActivity">

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:background="@color/toolbar_background_color"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:title="CAMPUS"
app:titleMarginStart="40dp"
app:titleTextAppearance="@style/ToolbarTitleText" />

<TextView
android:id="@+id/textView2"
android:layout_width="234dp"
android:layout_height="63dp"
android:layout_marginStart="16dp"
android:layout_marginTop="4dp"
android:fontFamily="@font/original_surfer"
android:text=" Explore Exciting Opportunities Beyond Campus!"
android:textSize="24sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar" />

<!-- Rounded Box Layout -->


<ImageView
android:id="@+id/imageView"
android:layout_width="166dp"
android:layout_height="113dp"
android:layout_marginStart="97dp"
android:layout_marginTop="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="@+id/textView2"
app:layout_constraintTop_toBottomOf="@+id/toolbar"
app:srcCompat="@drawable/supporting" />

<!-- Rounded Box Layout -->


<LinearLayout
android:id="@+id/rounded_box_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal"
android:padding="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView">

<!-- First Rounded Box -->


<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp">

<!-- Content inside the first rounded box -->


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp"
android:gravity="center">

<ImageView
android:layout_width="67dp"
android:layout_height="69dp"
android:layout_gravity="center_horizontal"
android:scaleType="centerCrop"
android:src="@drawable/job" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Off Campus Job"
android:textColor="@android:color/black"
android:textSize="12sp" />

</LinearLayout>
</androidx.cardview.widget.CardView>

<!-- Repeat the below block 3 more times to create 4 rounded boxes
in the same line -->
<!-- Second Rounded Box -->
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp">
<!-- Content inside the second rounded box -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp"
android:gravity="center">

<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:src="@drawable/coding"
android:scaleType="centerCrop"
android:layout_gravity="center_horizontal"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Practice Coding"
android:textSize="14sp"
android:textColor="@android:color/black"
android:gravity="center_horizontal"/>

</LinearLayout>
</androidx.cardview.widget.CardView>

<!-- Third Rounded Box -->


<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp">

<!-- Content inside the third rounded box -->


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp"
android:gravity="center">

<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:src="@drawable/intern"
android:scaleType="centerCrop"
android:layout_gravity="center_horizontal"/>

<TextView
android:layout_width="99dp"
android:layout_height="38dp"
android:gravity="center"
android:text="Internship Applications"
android:textColor="@android:color/black"
android:textSize="12sp" />

</LinearLayout>
</androidx.cardview.widget.CardView>
<!-- Fourth Rounded Box -->
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp">

<!-- Content inside the fourth rounded box -->


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="8dp">

<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_gravity="center_horizontal"
android:scaleType="centerCrop"
android:src="@drawable/read" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Read Campus Experience"
android:textColor="@android:color/black"
android:textSize="12sp" />

</LinearLayout>
</androidx.cardview.widget.CardView>

</LinearLayout>

<!-- Add Card Caraousel here -->


<!-- Add Card Carousel here -->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/RecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
app:layout_constraintTop_toBottomOf="@id/rounded_box_layout"
tools:layout_editor_absoluteX="96dp" />

</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</androidx.drawerlayout.widget.DrawerLayout>

//this is my MainActivity.java Code

package com.example.job;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.navigation.NavigationView;
import com.google.firebase.FirebaseApp;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

DrawerLayout drawerLayout;
NavigationView navigationView;
Toolbar toolbar;
RecyclerView recyclerView;
MyAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

drawerLayout = findViewById(R.id.drawerlayout);
navigationView = findViewById(R.id.navigationview);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,


drawerLayout, toolbar, R.string.navigration_open, R.string.navigration_close);
drawerLayout.addDrawerListener(toggle);
toggle.syncState();

// Initialize RecyclerView
recyclerView = findViewById(R.id.RecyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));

// Populate itemList with data


List<CarouselItem> itemList = new ArrayList<>();
itemList.add(new CarouselItem(R.drawable.image1, "Title 1"));
itemList.add(new CarouselItem(R.drawable.image2, "Title 2"));
// Add more items as needed

// Instantiate the adapter with the list of items


adapter = new MyAdapter(itemList);

// Set adapter for the RecyclerView


recyclerView.setAdapter(adapter);

FirebaseApp.initializeApp(this);
}
}

// this is my MyAdapter.java Class File

package com.example.job;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {


private List<CarouselItem> items;

public MyAdapter(List<CarouselItem> items) {


this.items = items;
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
// Inflate the layout file demo.xml
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.demo,
parent, false);
return new ViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
CarouselItem item = items.get(position);
// Bind data to the views
holder.imageView.setImageResource(item.getImageResource());
holder.textViewTitle.setText(item.getTitle());
holder.buttonAction.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Handle button click
}
});
}

@Override
public int getItemCount() {
return items.size();
}

public static class ViewHolder extends RecyclerView.ViewHolder {


ImageView imageView;
TextView textViewTitle;
Button buttonAction;
public ViewHolder(@NonNull View itemView) {
super(itemView);
imageView = itemView.findViewById(R.id.imageView);
textViewTitle = itemView.findViewById(R.id.textViewTitle);
buttonAction = itemView.findViewById(R.id.buttonAction);
}
}
}

// this is my item_card.xml file

<?xml version="1.0" encoding="utf-8"?>


<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dp"
android:layout_height="140dp"
android:layout_margin="8dp"
android:padding="8dp"
android:background="@color/black"
android:foreground="?android:attr/selectableItemBackground">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="130dp"
android:orientation="horizontal">

<!-- Left Rounded Image Area -->


<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:orientation="vertical"
android:padding="8dp">

<ImageView
android:id="@+id/imageView"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@color/black"
android:scaleType="centerCrop"
android:src="@drawable/coding" />

</LinearLayout>

<!-- Right Side: Text and Button -->


<LinearLayout
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">

<!-- Text -->


<TextView
android:id="@+id/textViewTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Weir Group Off Campus Careers 2024 Hiring As Graduate
Engineer Trainee For BE/BTech/ME/MTech/MCA"
android:textColor="@android:color/black"
android:textSize="16sp" />

<!-- Button -->


<Button
android:id="@+id/buttonAction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Apply Now" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>

//this is my CaraouselItem.java File

package com.example.job;

public class CarouselItem {


private int imageResource;
private String title;

public CarouselItem(int imageResource, String title) {


this.imageResource = imageResource;
this.title = title;
}

public int getImageResource() {


return imageResource;
}

public String getTitle() {


return title;
}
}

Now Check and Say Why My Card Carousel Not showing

You might also like