プログラミング初心者です。
Android studioを用いてアプリ開発を行いたいのですが、その際に、ボタンのテキストをユーザーが編集できるようにしたいです。
例えば、初めはボタンに「グループ1」等と記載してあり、アプリをダウンロード後、ユーザーがその名称を自由に編集できるようにしたいです。
ボタンはボタンとして使用できる状態を保持したいです。例)ボタンを押したら画面遷移できる。
以下のような方法を考えたのですが、プログラミング初心者でありまったくコードの書き方がわかりません…。
KotlinもしくはJavaを用いてご教示いただけますと幸いです。
ボタンの後ろにEditTextを配置し、別のボタンを押すとEditTextが前に配置されてテキストが編集可能になる
言語
Kotlin Java
コード (Activity)
package com.example.user.memo import android.content.Intent import android.support.v7.app.AppCompatActivity import android.os.Bundle import android.widget.Button class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_Main) // 画面遷移 ボタン val button: Button = this.findViewById(R.id.button1) button.setOnClickListener { val intent: Intent = Intent(this, NextActivity::class.java) startActivity(intent) } } }
コード (Layout)
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <android.support.constraint.ConstraintLayout android:layout_width="match_parent" android:layout_height="match_parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toBottomOf="parent"> <Button android:text="グループ1" android:layout_width="150dp" android:layout_height="60dp" android:id="@+id/button1" android:textSize="24sp" /> </android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>
回答1件
あなたの回答
tips
プレビュー