I'm noticing that by adding the HorizontalScrollView it's disabling my ability to select items on my ListView. This seems like a pretty basic/common feature to want to add (I want to be able to swipe my item to the left to offer a delete option) but HorizontalScrollView appears to be incompatible with items that you would like to also touch to select. Note that if I change HorizontalScrollView to a LinearLayout or otherwise the items become selectable.
I was suspecting that touch listeners may be ineffective due to the fact that the swiping capability overrides any other kind of touch, but I can't really think of why it doesn't work otherwise. Can anyone help to resolve this issue? I would like to be able to use HorizontalScrollView alongside a click compatibility (unless there is another way to achieve the same functionality).
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView
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:layout_height="match_parent"
android:scrollbars="none">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<android.support.constraint.ConstraintLayout
android:id="#+id/constraintLayout4"
android:layout_width="384dp"
android:layout_height="110dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/task_view_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="17dp"
android:layout_marginTop="28dp"
android:fontFamily="#font/robotolight"
android:text="#string/task_name"
android:textColor="#android:color/black"
android:textSize="24sp"
app:layout_constraintStart_toEndOf="#+id/task_view_icon"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/task_view_icon"
android:layout_width="77dp"
android:layout_height="77dp"
android:layout_marginStart="17dp"
android:layout_marginTop="17dp"
android:contentDescription="#+string/icon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/main_page_icon_switch_x4" />
<TextView
android:id="#+id/task_view_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="36dp"
android:fontFamily="#font/robotolight"
android:text="#string/duration"
android:textColor="#android:color/black"
android:textSize="14sp"
app:layout_constraintStart_toEndOf="#+id/task_view_name"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/task_view_detail"
android:layout_width="228dp"
android:layout_height="31dp"
android:layout_marginStart="17dp"
android:fontFamily="#font/robotolight"
android:text="#string/task_view_detail_literal"
android:textColor="#android:color/black"
android:textSize="12sp"
app:layout_constraintStart_toEndOf="#+id/task_view_icon"
app:layout_constraintTop_toBottomOf="#+id/task_view_name" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:id="#+id/task_delete"
android:layout_width="116dp"
android:layout_height="110dp"
android:background="#color/colorPrimary"
app:layout_constraintEnd_toEndOf="#id/constraintLayout4"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/task_delete_literal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="13dp"
android:layout_marginTop="39dp"
android:fontFamily="#font/roboto_regular"
android:text="#string/delete"
android:textColor="#android:color/background_light"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</LinearLayout>
</HorizontalScrollView>
For anyone having this problem, I managed to find a way to workaround this. My problem was that I could not click on the ListView item because of the HorizontalScrollView setup in the XML, however in my case I was using an adapter along with my ListView (that allows you link your listView with your actual list row view) and in that adapter I simply defined and linked the container of the view that I want to press and set an onClickListener.
This goes in your custom adapter:
ConstraintLayout myLayout = convertView.findViewById(R.id.constraintLayout1);
ConstraintLayout anotherLayout = convertView.findViewById(R.id.constraintLayout2); //lets' say I'm using this to delete the item when clicked
myLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent exampleIntent = new Intent(viewParent.getContext(), SomeActivity.class);
}
});
anotherLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(view.getContext());
builder.setMessage("Are You Sure?").setNegativeButton("No", null);
builder.setPositiveButton("yes", new android.support.v7.app.AlertDialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Database database = new Database(viewParent.getContext());
database.deleteItem(item);
List<Item> items = database.getItems();
ListView list = (ListView) viewParent.findViewById(R.id.my_linear_list);
//List<Item> items = new Database(viewParent.getContext()).getItems();
TaskAdapter adapterNew = new ItemAdapter(viewParent.getContext(), tasks);
list.setAdapter(adapterNew);
}
});
builder.show();
}
});
Related
I have a layout with three TextViews, two TextViews are responding to Click Events but the last one is not responding. I am using Navigation to navigate to other fragments. The OnClick method is called inside an adapter which implements view.OnClickListener.
XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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_marginStart="#dimen/defaultMargin"
android:layout_height="wrap_content">
<TextView
android:text="How CADO works"
style="#style/CircularBook"
android:drawableEnd="#drawable/arrow_right"
android:layout_width="0dp"
android:layout_height="#dimen/buttonHeight"
android:id="#+id/howCadoWorks"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<View
app:layout_constraintTop_toBottomOf="#id/howCadoWorks"
android:layout_width="match_parent"
android:background="#color/pinkishGray"
android:layout_height="0.5dp"
android:id="#+id/view3"></View>
<TextView
android:text="FAQ"
style="#style/CircularBook"
android:layout_width="0dp"
android:drawableEnd="#drawable/arrow_right"
android:layout_height="#dimen/buttonHeight"
android:id="#+id/faqs"
app:layout_constraintTop_toBottomOf="#+id/view3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<View
app:layout_constraintTop_toBottomOf="#id/faqs"
android:layout_width="match_parent"
android:background="#color/pinkishGray"
android:layout_height="0.5dp"
android:id="#+id/view4"></View>
<TextView
android:text="Contact Us"
android:drawableEnd="#drawable/arrow_right"
style="#style/CircularBook"
android:layout_width="0dp"
android:layout_height="#dimen/buttonHeight"
android:id="#+id/contactus"
app:layout_constraintTop_toBottomOf="#+id/view4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
OnClickMethod
public void onClick(#Nullable View view) {
NavController var3 = Navigation.findNavController(view);
if(view.getId()==R.id.contactus){
**var3.navigate(R.id.contactus_fragment);**
return;
}
else if (view.getId()==R.id.faqs){
var3.navigate(R.id.faqFragmnt);
return;
}
else if (view.getId()==R.id.howCadoWorks){
Toast.makeText(view.getContext(),"Feature is in Progress", Toast.LENGTH_SHORT).show();
// var3.navigate(R.id.contactus_fragment);
return;
}
else
{
}
}
I have tried multiple ways, rechecked id's as well but nothing is working.
as #Nilesh Rathod said, you need to make sure that all your text view have set an on click listener like:
textView.setOnClickListener(this);
or you can also:
textView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// Here you put the code you want to use for the specific textView click event
}
});
I have an alert dialog which popups when you click a button in my app. The code is pretty simple and can be seen below:
final String[] options = {"Bar Graph", "Pie Chart", "Text Summary"};
AlertDialog.Builder builder = new AlertDialog.Builder(myActivity.this);
builder.setTitle("Choose a summary");
builder.setIcon(R.drawable.summaryicon);
builder.setItems(options, ... );
See below an image of what it looks like. This is good.
However, strangely sometimes when I build my app on the emulator the theme of the alert dialog changes and looks like this instead:
I cannot imagine what would be causing this random change in a seemingly unpredictable way.
I have tried using this line to set the theme manually, but it seems to have no effect.
ContextThemeWrapper themedContext = new ContextThemeWrapper( AnalysisActivity.this, android.R.style.ThemeOverlay_Material_Dialog_Alert );
AlertDialog.Builder builder = new AlertDialog.Builder(themedContext);
...
I am confused and looking for a way to set the theme manually or ensure it doesn't change from the default.
I can't entirely tell if the rest of my app also experiences the same theme change because most has all been overridden by custom code, but I don't believe it is changing. Any ideas would be welcome.
Note: this alternate theme looks like an older theme so perhaps there is some version issue?
try this code...
step-1: create layout file of your alert dialog(this layout is your designed alertDialog)
step-2: and use this code
public void displayAlertDialog() {
LayoutInflater factory = LayoutInflater.from(this);
final View alertDialogView = factory.inflate(R.layout.alert_dialog, null);
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setView(alertDialogView);
alertDialogView.findViewById(R.id.bar_graph).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//your business logic
alertDialog.dismiss();
}
});
alertDialogView.findViewById(R.id.pie_chart).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//your business logic
alertDialog.dismiss();
}
});
alertDialogView.findViewById(R.id.text_summary).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//your business logic
alertDialog.dismiss();
}
});
alertDialog.show();
}
Along with Dinesh Sarma's answer the code I have now implemented to create the alertdialog activity can be seen here.
It creates a layout that looks like this:
Use this layout code in a file called alert_dialog.xml:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/background_light"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/background_light"
android:orientation="horizontal"
android:weightSum="12">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_weight="7"
android:contentDescription="Icon"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:scaleType="fitCenter"
app:srcCompat="#drawable/summaryicon" />
<TextView
android:id="#+id/textView13"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="5"
android:gravity="center_vertical"
android:text="Choose a Summary"
android:textSize="18sp"
android:textStyle="normal" />
</LinearLayout>
<Button
android:id="#+id/bar_graph"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="#android:color/background_light"
android:gravity="center_vertical"
android:paddingStart="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="Pie Chart"
android:textAllCaps="false"
android:typeface="sans" />
<Button
android:id="#+id/pie_chart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="#android:color/background_light"
android:gravity="center_vertical"
android:paddingStart="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="Bar Graph"
android:textAllCaps="false"
android:typeface="sans" />
<Button
android:id="#+id/text_summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="#android:color/background_light"
android:gravity="center_vertical"
android:paddingStart="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="Text Summary"
android:textAllCaps="false"
android:typeface="sans" />
</LinearLayout>
I want to make a ListView, when you long click on an item, the item will be added to the buttons: delete and update (only the clicked item):
So I have made a ListView in my MainLayout:
<ListView
android:id="#+id/neighborhood"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="#+id/allAddresses"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/AddresSearch" />
and a Custom ListView Item lay out, which contains 3 TextViews:
<android.support.constraint.ConstraintLayout 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/button_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".passItemView">
<TextView
android:id="#+id/num"
android:layout_width="86dp"
android:layout_height="45dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="28dp"
android:text="cv"
app:layout_constraintEnd_toStartOf="#+id/house"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/house"
android:layout_width="86dp"
android:layout_height="45dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="32dp"
android:text="cvc"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/pass"
android:layout_width="86dp"
android:layout_height="45dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="32dp"
android:text="cv"
app:layout_constraintEnd_toStartOf="#+id/num"
app:layout_constraintTop_toTopOf="parent" />
and this layout is conneted to a class "passItemView", and there, what I did is that on longClick on the layout it will add 2 button (or even just will make a toast)
But it does nothing.
public class passItemView extends AppCompatActivity {
Button delete = new Button(this);
Button update = new Button(this);
ConstraintLayout btnLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pass_item_view);
btnLayout = (ConstraintLayout) findViewById(R.id.button_layout);
btnLayout.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
Toast.makeText(passItemView.this,"Toast it",Toast.LENGTH_LONG).show();
btnLayout.addView((delete));
btnLayout.addView((update));
return false;
}
});
Thank you for your Help.
use an boolean value (ex : showButtons) and initialize set it false for all items.
when you clicked someitem make items showButtons variable true and notifydatasetchange (reload lsitview) again.
I want to animate text in my textswitcher. I went through all the stack questions and the documentation, but they didn't solve my problem.
Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="match_parent">
<TextView
android:id="#+id/tv__inc_pre_sing__screen_title"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#fff"
android:gravity="center"
android:text="PRACTICE"
android:textAllCaps="true"
android:textColor="#color/colorAccent"
android:textSize="16dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.ConstraintLayout
android:id="#+id/rl__inc_pre_sing__tm_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="#efff"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/tv__inc_pre_sing__screen_title">
<ImageView
android:id="#+id/tv__inc_pre_sing__quotation_mark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:src="#drawable/ic_archive_black_24dp"
app:layout_constraintTop_toTopOf="parent" />
<TextSwitcher
android:id="#+id/tv__inc_pre_sing__teacher_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/tv__inc_pre_sing__quotation_mark"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:src="#drawable/ic_archive_black_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/tv__inc_pre_sing__teacher_message" />
</android.support.constraint.ConstraintLayout>
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:text="Click Me"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<View
android:layout_width="0dp"
android:layout_height="16dp"
android:background="#drawable/ic_launcher_background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/rl__inc_pre_sing__tm_container" />
</android.support.constraint.ConstraintLayout>
Here is my code
public class Main3Activity extends AppCompatActivity {
private TextSwitcher mSwitcher;
Button btnNext;
int currentIndex=-1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
Resources resources = getApplicationContext().getResources();
final String[] textString = resources.getStringArray(R.array.teacher_messages);
btnNext = findViewById(R.id.button);
mSwitcher = findViewById(R.id.tv__inc_pre_sing__teacher_message);
mSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
public View makeView() {
// TODO Auto-generated method stub
// create new textView and set the properties like clolr, size etc
TextView myText = new TextView(Main3Activity.this);
myText.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
myText.setTextColor(Color.BLUE);
return myText;
}
});
// Declare the in and out animations and initialize them
Animation in = AnimationUtils.loadAnimation(this,android.R.anim.slide_in_left);
Animation out = AnimationUtils.loadAnimation(this,android.R.anim.slide_out_right);
// set the animation type of textSwitcher
mSwitcher.setInAnimation(in);
mSwitcher.setOutAnimation(out);
// ClickListener for NEXT button
// When clicked on Button TextSwitcher will switch between texts
// The current Text will go OUT and next text will come in with specified animation
btnNext.setOnClickListener(new View.OnClickListener() {
//
public void onClick(View v) {
// TODO Auto-generated method stub
currentIndex++;
// If index reaches maximum reset it
if(currentIndex==textString.length)
currentIndex=0;
mSwitcher.setText(textString[currentIndex]);
((ViewGroup) findViewById(R.id.rl__inc_pre_sing__tm_container)).getLayoutTransition()
.enableTransitionType(LayoutTransition.CHANGING);
}
});
}
}
The animation on ConstraintLayout whose id is rl__inc_pre_sing__tm_container does not work properly. Suppose my TextSwitcher has text whose length is greater than 3 and then TextSwitcher shows text whose length is 1 then the ConstraintLayout does not animate, if the next text is of length 1 then the constraintlayout animates.
I am not able to figure out this weird behaviour.
Here is the issue: When the TextSwitcher transitions from X lines of text to something less than X lines then the TextSwitcher's height does not change.
The TextSwitcher inherits some behavior from ViewAnimator which considers the height of all views when determining the height of the widget. The solution is to add the following XML to the TextSwitcher definition in the layout file that will inhibit this behavior:
android:measureAllChildren="false"
Thanks to this Stack Overflow answer that states all this better than I have.
I have a ListView that I have customized to display information gathered from an SQLite database. Each item is a represented using a CardView widget containing TextViews. I have set the ListView property in the .xml file to:
android:choiceMode="singleChoice"
allowing the user to make a selection from the list.
When the user clicks the floating action button, I want to be able to take information displayed in one of the TextViews of the CardView selected in the ListView.
I have looked at other questions on the topic and they suggest using the onClick method, but I do not understand how that would work because I do not want to retrieve the information when the user makes the selection from the list. Rather, I want the information when they have selected the floating action button.
Here is part of my Activity code:
public class SetViewerActivity extends AppCompatActivity {
private static final String TAG = "SetViewerActivity";
private boolean fabState;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// set contents of activity
setContentView(R.layout.activity_set_viewer);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// set action for main floating action button
FloatingActionButton fab = (FloatingActionButton)
findViewById(R.id.fab);
fabState = false;
fab.setOnClickListener(new View.OnClickListener() {
// get set info and edit in new Activity
#Override
public void onClick(View view) {
editSelectedSet(view);
}
});
// set up list view and populate with custom set info from database
SQLiteDatabase db = new MemCardSQLiteHelper(this).getReadableDatabase();
Cursor cursor = db.rawQuery(MemCardDbContract.Sets.SELECT_ALL_SETS,
null);
ListView lvSets = (ListView) findViewById(R.id.listViewSets);
SetViewAdapter adapter = new SetViewAdapter(this, cursor);
lvSets.setAdapter(adapter);
}
private void editSelectedSet(View view) {
// HOW DO I FIND THE SET INFORMATION HERE ??
// start activity with selected set information for editing
Intent intent = new Intent(this, CreateNewSet.class);
intent.putExtra(MainActivity.CREATE_SET_NUM, selectedSet);
startActivity(intent);
}
}
and here is my xml for each ListView item:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp">
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:cardCornerRadius="4dp"
app:cardElevation="2dp"
app:contentPadding="2dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textViewName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textViewAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textViewName" />
<TextView
android:id="#+id/textViewColour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintTop_toBottomOf="#+id/textViewAmount" />
<TextView
android:id="#+id/textViewSetId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
You can assign an onClick on each item and when an item is selected (clicked) than you can save the data as a field member. Then read the data where ever you want.