1. Home Fragment
package com.example.arman.myapplication;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.List;
/** * A simple {@link Fragment} subclass. */public class Home_Fragment extends Fragment {
public Home_Fragment() {
// Required empty public constructor }
RecyclerView recyclerView;
ArmanRecyclerAdapter adapter;
ArrayList<String> headerr = new ArrayList<>();
ArrayList<String> descc = new ArrayList<>();
ArrayList<Integer> imagee = new ArrayList<Integer>();
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_home_, container, false);
recyclerView = view.findViewById(R.id.reCyclid);
headerr.add("The conference opened with Silicon Valley facing a wave of criticism");
descc.add("\"It´s clear that technology can be a positive force and improve the quality of life for billions of people around the world.\" Pichai said.\n" +
"\n" +
"\"But it´s equally clear that we can´t just be wide-eyed about what we create.\"\n" +
"\n" +
"He added that \"we feel a deep sense of responsibility to get this right.\"\n" +
"\n" +
"Much of the focus was on Google Assistant, the artificial intelligence application competing against Amazon´s Alexa and others.\n" +
"\n" +
"Google Assistant is being taught to better understand people and interact with them more naturally -- and will be getting new voices, including one based on the voice of singer John Legend, as well as programming to improve conversation performance.\n" +
"\n" +
"\"Thanks to our progress in language understanding, you´ll soon be able to have a natural back-and-forth conversation with the Google Assistant without repeating ´Hey Google´ for each follow-up request,\" Pichai said.");
imagee.add(R.drawable.b);
headerr.add("Google pitches artificial intelligence to help unplug");
descc.add("AFP\n" +
"May 9, 2018\n" +
" \n" +
"HomeLatestSci-Tech\n" +
"Google pitches artificial intelligence to help unplug\n" +
"\n" +
"\n" +
"\n" +
"MOUNTAIN VIEW: Google unveiled Tuesday an artificial intelligence tool capable of handling routine tasks -- such as making restaurant bookings -- as a way to help people disconnect from their smartphone screens.\n" +
"\n" +
"Kicking off the tech giant´s annual developers conference, Google chief executive Sundar Pichai argued that its AI-powered digital assistant had the potential to free people from everyday chores.\n" +
"\n" +
"Pichai played a recording of the Google Assistant independently calling a hair salon and a restaurant to make bookings -- interacting with staff who evidently didn´t realize they were dealing with artificial intelligence software, rather than a real customer.\n" +
"\n" +
"Tell the Google Assistant to book a table for four at 6:00 pm, it tends to the phone call in a human-sounding voice complete with \"ums\" and \"likes,\" and sends you a message with the details.\n" +
"\n" +
"\"Our vision for our assistant is to help you get things done,\" Pichai told the conference in Google´s hometown of Mountain View, California.\n" +
"\n" +
"\"It turns out that a big part of getting things done is making a phone call.\"\n" +
"\n" +
"Google will be testing the digital assistant improvement in the months ahead.");
imagee.add(R.drawable.a);
recyclerView.setHasFixedSize(true);
GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(),2);
recyclerView.setLayoutManager(gridLayoutManager);
adapter = new ArmanRecyclerAdapter(getContext(),headerr,descc,imagee);
recyclerView.setAdapter(adapter);
return view;
}
}
2. ArmanRecyclerAdapter
package com.example.arman.myapplication;
import android.content.Intent;
import android.support.v4.app.FragmentManager;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import java.util.ArrayList;
public class ArmanRecyclerAdapter extends RecyclerView.Adapter<ArmanRecyclerAdapter.Habib> {
Context context;
ArrayList<String> header_Arry = new ArrayList<>();
ArrayList<String> desc_Arry = new ArrayList<>();
ArrayList<Integer> image_Arry = new ArrayList<>();
public ArmanRecyclerAdapter(Context context, ArrayList<String> header_Arry, ArrayList<String> desc_Arry, ArrayList<Integer> image_Arry) {
this.context = context;
this.header_Arry = header_Arry;
this.desc_Arry = desc_Arry;
this.image_Arry = image_Arry;
}
@NonNull @Override public Habib onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.item, parent, false);
Habib habib = new Habib(view);
return habib;
}
@Override public void onBindViewHolder(@NonNull final Habib holder, final int position) {
holder.header.setText(header_Arry.get(position));
holder.desc.setText(desc_Arry.get(position));
Glide.with(context)
.asBitmap()
.load(image_Arry.get(position))
.into(holder.imageView1);
holder.linearLayout.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
Intent intent = new Intent(context, DataPassingActivity.class);
intent.putExtra("header", header_Arry.get(position));
intent.putExtra("desc", desc_Arry.get(position));
intent.putExtra("image", image_Arry.get(position));
context.startActivity(intent);
}
});
}
@Override public int getItemCount() {
return header_Arry.size();
}
class Habib extends RecyclerView.ViewHolder {
ImageView imageView1;
TextView header, desc;
LinearLayout linearLayout;
public Habib(View itemView) {
super(itemView);
imageView1 = itemView.findViewById(R.id.imageid);
header = itemView.findViewById(R.id.header);
desc = itemView.findViewById(R.id.desc);
linearLayout = itemView.findViewById(R.id.linearlayout);
}
}
}
3. DataPassingActivity
(এই Activity তে ডাটা রিসিভ হবে)
package com.example.arman.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
public class DataPassingActivity extends AppCompatActivity {
TextView hdd, dscc;
ImageView imgg;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_data_passing);
hdd = findViewById(R.id.headerData);
dscc = findViewById(R.id.descData);
imgg = findViewById(R.id.imageData);
arman();
}
void arman() {
if (getIntent().hasExtra("header") && getIntent().hasExtra("desc") && getIntent().hasExtra("image")) {
{
String header = getIntent().getStringExtra("header");
String desc = getIntent().getStringExtra("desc");
int image = getIntent().getIntExtra("image",R.drawable.a);
hdd.setText(header);dscc.setText(desc);
Glide.with(this)
.asBitmap()
.load(image)
.into(imgg);
}
}
}
}
3.1. DataPassingActivity.XML
<?xml version="1.0" encoding="utf-8"?><ScrollView 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:layout_width="match_parent" android:orientation="vertical" android:layout_height="match_parent" tools:context=".DataPassingActivity">
<LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent">
<TextView android:text="Header" android:id="@+id/headerData" android:textSize="20sp" android:textStyle="bold" android:textAlignment="center" android:layout_margin="10sp" android:layout_width="match_parent" android:layout_height="wrap_content" />
<ImageView android:layout_margin="10sp" android:id="@+id/imageData" android:layout_width="match_parent" android:layout_height="150sp" />
<TextView android:layout_margin="10sp" android:text="description" android:id="@+id/descData" android:layout_width="match_parent" android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
4. Item.XML (must Important)
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/linearlayout" android:layout_margin="4dp" android:layout_width="wrap_content" android:layout_height="135dp">
<android.support.v7.widget.CardView app:cardElevation="10sp" android:layout_margin="4dp" android:layout_marginBottom="4sp" android:layout_width="wrap_content" android:layout_height="135sp">
<RelativeLayout android:layout_width="195dp" android:layout_height="match_parent" android:orientation="horizontal" >
<TextView android:id="@+id/header" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="3sp" android:layout_marginRight="3sp" android:maxLines="2" android:text="ldkfjsldfjlk" android:textAlignment="center" android:textColor="#000000" android:textSize="16sp" android:textStyle="bold" />
<TextView android:paddingTop="3sp" android:id="@+id/desc" android:textSize="15sp" android:layout_width="92dp" android:layout_height="84dp" android:layout_alignParentEnd="true" android:layout_alignParentTop="true" android:layout_marginTop="45dp" android:text="dslkfj sdfkljs fkljfkldsfskldfj" />
<ImageView android:scaleType="fitXY" android:id="@+id/imageid" android:layout_width="95dp" android:layout_height="89dp" android:layout_alignParentBottom="true" android:layout_alignParentStart="true" android:src="@drawable/b" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
0 Comments