Skip to content

Instantly share code, notes, and snippets.

@isfaaghyth
Created January 21, 2017 18:37
Show Gist options
  • Save isfaaghyth/b1a25611f67daca75fb7ae5cfbe993a1 to your computer and use it in GitHub Desktop.
Save isfaaghyth/b1a25611f67daca75fb7ae5cfbe993a1 to your computer and use it in GitHub Desktop.
Show-Hide content on Cardview
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Load More!"
android:textSize="17sp"
android:textStyle="bold" />
<Button
android:id="@+id/btn_load_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show"/>
<TextView
android:id="@+id/txt_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hai!"
android:textSize="17sp"
android:textStyle="bold"
android:visibility="gone"
android:layout_marginStart="10dp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
public class MainActivity extends AppCompatActivity {
@BindView(R.id.btn_load_more)
Button btnLoadMore;
@BindView(R.id.txt_more)
TextView txtMore;
boolean showContent = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
}
@OnClick(R.id.btn_load_more)
public void onLoadMore() {
if (showContent) {
txtMore.setVisibility(View.VISIBLE);
btnLoadMore.setText("Hide");
showContent = false;
} else {
txtMore.setVisibility(View.GONE);
btnLoadMore.setText("Show");
showContent = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment