Hi sorry for my bad title (i really dont know how to phrase it better) but i have a cardview just like this cardview where the result/s returned are based on the user has input on the search bar.
All of the information returned are based on my database (DB Browser for SQLite). the cardview itself is not clickable but now I want the related keyword section to be clickable in a way where if a user click on one of the related keywords, it will open the cardview of that keyword like the same way when if the user search on it. (pardon me for my bad english!) As of now I only know that I have to add the clickable=true on the UI. However, logic-wise, I am not sure.
Below are my codes:
Cardview UI
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="5dp"
android:layout_margin="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="8dp">
<LinearLayout
android:orientation="vertical"
android:layout_weight="9"
android:layout_width="0dp"
android:layout_height="wrap_content">
<TextView
android:id="@+id/keyword"
android:layout_marginLeft="10dp"
android:gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
android:textSize="15dp"
android:text="Baggage Management Interface Device (BMID) Testing
123"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/acronym"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical|start"
android:textStyle="italic"
android:textColor="#a8000000"
android:text="GST"
android:textSize="13dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/description"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical|start"
android:textColor="#a8000000"
android:text="If none are set then 'GST' is set to NULL"
android:textSize="13dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/relatedKeyword"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical|start"
android:textColor="#a8000000"
android:text="Related Keyword:"
android:textSize="12sp"
android:textStyle="bold|italic"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/relatedKeyword1"
android:clickable="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:textColor="#a8000000"
android:text="Keyword 1"
android:textSize="12sp"
android:textStyle="italic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/relatedKeyword2"
android:clickable="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:textColor="#a8000000"
android:text="Keyword 2"
android:textSize="12sp"
android:textStyle="italic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/relatedKeyword3"
android:clickable="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:textColor="#a8000000"
android:text="Keyword 3"
android:textSize="12sp"
android:textStyle="italic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Search Adapter + SearchView Holder
package com.example.run_h.boav2.Adapter;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.example.run_h.boav2.Model.Knowledge;
import com.example.run_h.boav2.R;
import java.util.List;
class SearchViewHolder extends RecyclerView.ViewHolder{
public TextView keyword, description, acronym, relatedkeyword1,
relatedkeyword2, relatedkeyword3;
public SearchViewHolder(@NonNull View itemView) {
super(itemView);
keyword = itemView.findViewById(R.id.keyword);
acronym = itemView.findViewById(R.id.acronym);
description = itemView.findViewById(R.id.description);
relatedkeyword1= itemView.findViewById(R.id.relatedKeyword1);
relatedkeyword2= itemView.findViewById(R.id.relatedKeyword2);
relatedkeyword3= itemView.findViewById(R.id.relatedKeyword3);
}
}
public class SearchAdapter extends RecyclerView.Adapter<SearchViewHolder>
{
private Context context;
private List<Knowledge> knowledge;
public SearchAdapter(Context context, List<Knowledge> knowledge) {
this.context = context;
this.knowledge = knowledge;
}
@NonNull
@Override
public SearchViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View itemView = inflater.inflate(R.layout.layout_item, parent,
false);
return new SearchViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull SearchViewHolder holder, int position)
{
holder.keyword.setText(knowledge.get(position).getKeyword());
holder.description.setText(knowledge.get(position).getDescription());
holder.acronym.setText(knowledge.get(position).getAcronym());
holder.relatedkeyword1.setText(knowledge.get(position).getRelatedkeyword1());
holder.relatedkeyword2.setText(knowledge.get(position).getRelatedkeyword2());
holder.relatedkeyword3.setText(knowledge.get(position).getRelatedkeyword3());
}
@Override
public int getItemCount() {
return knowledge.size();
}
}
Anyone knows how I can implement this? Much appreciated. Thanks!