Estoy usando un "FloatingActionButton". A continuación adjunto algunas imagenes para explicar mas a detalle. Click Aquí para ver la Imágen
Estoy utilizando RecylerView, implementé un boton flotante que este mismo se repite en todos los Items, Pero al darle funcion, Ejemplo: un Intent. Este se repite en los demás. No quiero eso; quiero que sea evento individual.
MAINACTIVITY.JAVA
private final String JSON_URL = "https://gist.githubusercontent.com/albeiro3/dc78fb430420f2cccea6ebd5b2679946/raw/1bb2cd18c3ad4bad5ff7249e6a82c0794f5804aa/anime.json" ;
private JsonArrayRequest request ;
private RequestQueue requestQueue ;
private List<Anime> lstAnime ;
private RecyclerView recyclerView ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lstAnime = new ArrayList<>() ;
recyclerView = findViewById(R.id.recyclerviewid);
jsonrequest();
}
private void jsonrequest() {
request = new JsonArrayRequest(JSON_URL, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
JSONObject jsonObject = null ;
for (int i = 0 ; i < response.length(); i++ ) {
try {
jsonObject = response.getJSONObject(i) ;
Anime anime = new Anime() ;
anime.setName(jsonObject.getString("name"));
anime.setDescription(jsonObject.getString("description"));
anime.setRating(jsonObject.getString("Rating"));
anime.setCategorie(jsonObject.getString("categorie"));
anime.setNb_episode(jsonObject.getInt("episode"));
anime.setStudio(jsonObject.getString("studio"));
anime.setImage_url(jsonObject.getString("img"));
anime.setSms(jsonObject.getString("sms"));
anime.setSms(jsonObject.getString("sms"));
lstAnime.add(anime);
} catch (JSONException e) {
e.printStackTrace();
}
}
setuprecyclerview(lstAnime);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
requestQueue = Volley.newRequestQueue(MainActivity.this);
requestQueue.add(request);
}
private void setuprecyclerview(List<Anime> lstAnime) {
RecyclerViewAdapter myadapter = new RecyclerViewAdapter(this,lstAnime) ;
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(myadapter);
}
}
PELICULASACTIVITY.JAVA
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_anime);
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "PRUEBA", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
getSupportActionBar().hide();
String name = getIntent().getExtras().getString("anime_name");
String description = getIntent().getExtras().getString("anime_description");
String studio = getIntent().getExtras().getString("anime_studio") ;
String category = getIntent().getExtras().getString("anime_category");
int nb_episode = getIntent().getExtras().getInt("anime_nb_episode") ;
String rating = getIntent().getExtras().getString("anime_rating") ;
String image_url = getIntent().getExtras().getString("anime_img") ;
String sms = getIntent().getExtras().getString("anime_sms") ;
CollapsingToolbarLayout collapsingToolbarLayout = findViewById(R.id.collapsingtoolbar_id);
collapsingToolbarLayout.setTitleEnabled(true);
TextView tv_name = findViewById(R.id.aa_anime_name);
TextView tv_studio = findViewById(R.id.aa_studio);
TextView tv_categorie = findViewById(R.id.aa_categorie) ;
TextView tv_description = findViewById(R.id.aa_description);
TextView tv_rating = findViewById(R.id.aa_rating);
ImageView img = findViewById(R.id.aa_thumbnail);
Button Sms = findViewById(R.id.aa_sms);
tv_name.setText(name);
tv_categorie.setText(category);
tv_description.setText(description);
tv_rating.setText(rating);
tv_studio.setText(studio);
Sms.setOnClickListener(this);
collapsingToolbarLayout.setTitle(name);
RequestOptions requestOptions = new RequestOptions().centerCrop().placeholder(R.drawable.loading_shape).error(R.drawable.loading_shape);
Glide.with(this).load(image_url).apply(requestOptions).into(img);
}
}
ACTIVITY_MAIN.XML
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.demotxt.myapp.myapplication.activities.MainActivity" android:background="#303030"> <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="16dp" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:id="@+id/recyclerviewid"></android.support.v7.widget.RecyclerView>
ANIME_ROW_ACTIVITY.XML
xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="150dp" android:layout_marginTop="5dp" android:padding="8dp" android:background="@drawable/bgg" android:id="@+id/container"> <ImageView android:layout_width="100dp" android:layout_height="match_parent" android:background="@drawable/loading_shape" android:id="@+id/thumbnail"/> <LinearLayout android:layout_width="match_parent" android:layout_height="130dp" android:orientation="vertical" android:layout_margin="8dp"> <TextView android:textColor="#fff" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/anime_name" android:text="Anime Title" android:textStyle="bold" android:textSize="18sp"/> <TextView android:textColor="#fff" android:layout_marginTop="5dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Category" android:id="@+id/categorie"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/rating" android:text="0.0" android:layout_marginTop="10dp" android:background="@drawable/rating_background" android:textColor="#fff" android:textSize="15sp" android:textStyle="bold" android:drawableLeft="@drawable/ic_star_black_24dp" android:paddingRight="5dp"/> <Button android:textColor="#fff" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="SMS" android:layout_marginTop="5dp" android:id="@+id/aa_sms"/> <TextView android:textColor="#fff" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Studio" android:layout_marginTop="5dp" android:id="@+id/studio"/> </LinearLayout>
En ANIME_ACTIVITY.JAVA le coloque al boton flotante un "Snackbar.make" para hacer una prueba y este se repite en todos. Si alguna cosa me falta, Favor me ayudarías!!! Gracias. Click Aquí para ver la imagen
NOTA: Soy Principiante, Tengo Poco conocimiento estoy aprendiendo un poco de programación, espero me entiendan, gracias