I am new to Android programming and was working on a card layout. I was wondering, how do I make it clickable?
android:clickable=\"true\"
android:foreground=\"?
You could implement the View.OnClickListener()
interface to your class and then in your onCreate()
method you could write findViewById(R.id.cardview).setOnClickListener(this)
. You could then Override the onClick()
method and do what you want to do when the user clicks the card.
It would look like this:
public class MainActivity extends Activity implements View.OnClickListener()
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// load the layout
setContentView(R.layout.filters);
// get the id of the CardView and attach an onClickListener to it
findViewById(R.id.cardList).setOnClickListener(this)
}
@Override
private void onClick(View view)
{
if(view.getId == R.id.cardList)
{
//Do something Like starting an activity
Intent intent = new Intent(MyActivity.this, NextActivity.class);
startActivity(intent);
}
}
}