Skip to content

Instantly share code, notes, and snippets.

View douglasiacovelli's full-sized avatar

Douglas Iacovelli douglasiacovelli

  • @contratadome
  • Bertioga
View GitHub Profile
class ListActivity: AppCompatActivity {
private val REQUEST_FORM = 1
onCreate(...){...}
fun startFormActivity() {
val intent = Intent(this, FormActivity::class.java)
startActivityForResult(intent, REQUEST_FORM)
}
class FormActivity: AppCompatActivity {
onCreate(...){...}
fun sendFormAndGoBack(name: String) {
// if you want to send any type of data back, such as an object, string, int etc
// you have to create an intent and use this bit of code
// otherwise you can just use setResult(Activity.RESULT_OK) and finish()
val resultIntent = Intent()
class ListActivity: AppCompatActivity {
private val REQUEST_FORM = 1
onCreate(...){...}
fun startFormActivity() {...}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
// check if the requestCode is the wanted one and if the result is what we are expecting
<resources>
<style name="HeadlineText">
<item name="android:textSize">?attr/headlineTextSize</item>
<item name="android:textColor">@color/dark_concrete</item>
</style>
</resources>
<LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Billing Info"
style="@style/HeadlineText" />
</LinearLayout>
<?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="134dp"
android:layout_height="154dp"
android:background="@drawable/grey_rounded_background"
android:gravity="center"
android:padding="16dp">
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="BenefitView">
<attr name="image" format="reference"/>
<attr name="text" format="string"/>
</declare-styleable>
</resources>
class BenefitView(context: Context, attrs: AttributeSet): LinearLayout(context, attrs) {
init {
inflate(context, R.layout.benefit_view, this)
val imageView: ImageView = findViewById(R.id.image)
val textView: TextView = findViewById(R.id.caption)
val attributes = context.obtainStyledAttributes(attrs, R.styleable.BenefitView)
imageView.setImageDrawable(attributes.getDrawable(R.styleable.BenefitView_image))
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.iacovelli.customview.MainActivity">
<HorizontalScrollView
<com.iacovelli.customview.BenefitView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:text="Apply and chat with our hosts"
app:image="@drawable/first_image"
android:layout_marginEnd="12dp"/>