AndroidのViewについて詰まったので質問させてただ来ます。
編集ボタンをクリックするとTextViewがEditTextに変わって、編集ボタンが完了ボタンになる。
このような機能の実装方法がわかりません。
解決方法よろしくお願いします。
気になる質問をクリップする
クリップした質問は、後からいつでもMYページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
回答2件
0
ベストアンサー
EditTextをsetEnable(false)にしておくと
タップしても状態が変わらないのでTextViewのように扱えます。
編集ボタンタップ時にsetEnable(true)にすれば通常のEditTextになるので編集可能となります。
見た目(背景、文字色、文字サイズ)等はこのタイミングで変更すれば良いでしょう。
同時にフォーカスも明示的に与えてやればキーボード等も出てくるかと思います。
投稿2014/12/24 10:36
総合スコア38
0
もっとかっこいい方法があると思いますが編集ボタンの押下時にVisibilityを切り替えるのはどうでしょうか?
lang
1<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical" 6 android:paddingBottom="@dimen/activity_vertical_margin" 7 android:paddingLeft="@dimen/activity_horizontal_margin" 8 android:paddingRight="@dimen/activity_horizontal_margin" 9 android:paddingTop="@dimen/activity_vertical_margin" 10 tools:context="com.example.test.MainActivity" > 11 12 <LinearLayout 13 android:layout_width="match_parent" 14 android:layout_height="wrap_content" 15 android:orientation="horizontal" > 16 17 <TextView 18 android:id="@+id/textView1" 19 android:layout_width="wrap_content" 20 android:layout_height="wrap_content" 21 android:text="@string/hello_world" /> 22 23 <EditText 24 android:id="@+id/editText1" 25 android:layout_width="wrap_content" 26 android:layout_height="wrap_content" 27 android:layout_marginTop="17dp" 28 android:ems="10" 29 android:visibility="gone" /> 30 </LinearLayout> 31 32 <LinearLayout 33 android:layout_width="match_parent" 34 android:layout_height="wrap_content" > 35 36 <Button 37 android:id="@+id/button1" 38 android:layout_width="wrap_content" 39 android:layout_height="wrap_content" 40 android:text="編集" /> 41 42 <Button 43 android:id="@+id/button2" 44 android:layout_width="wrap_content" 45 android:layout_height="wrap_content" 46 android:text="完了" 47 android:visibility="gone" /> 48 </LinearLayout> 49 50</LinearLayout>
lang
1private Button mButton1; // 編集 2private Button mButton2; // 完了 3private EditText mEditText; 4private TextView mTextView; 5 6@Override 7protected void onCreate(Bundle savedInstanceState) { 8 super.onCreate(savedInstanceState); 9 setContentView(R.layout.activity_main); 10 mButton1 = (Button) findViewById(R.id.button1); 11 mButton1.setOnClickListener(new OnClickListener() { 12 @Override 13 public void onClick(View v) { 14 mButton1.setVisibility(View.GONE); 15 mButton2.setVisibility(View.VISIBLE); 16 mEditText.setVisibility(View.VISIBLE); 17 mTextView.setVisibility(View.GONE); 18 } 19 }); 20 mButton2 = (Button) findViewById(R.id.button2); 21 mEditText = (EditText) findViewById(R.id.editText1); 22 mTextView = (TextView) findViewById(R.id.textView1); 23} 24
投稿2014/12/22 05:47
総合スコア410
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
あなたの回答
tips
太字
斜体
打ち消し線
見出し
引用テキストの挿入
コードの挿入
リンクの挿入
リストの挿入
番号リストの挿入
表の挿入
水平線の挿入
プレビュー
質問の解決につながる回答をしましょう。 サンプルコードなど、より具体的な説明があると質問者の理解の助けになります。 また、読む側のことを考えた、分かりやすい文章を心がけましょう。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。