私はListViewの値を持っていますが、その値を編集してコンテキストメニューを開くことで各値を編集可能にしたいと考えています。 ListViewでアイテムをクリックすると表示されるコンテキストメニューにEditTextフィールドを追加するにはどうすればよいですか?上記の問題についてより良い考えがある場合は、お気軽にご提案ください。答えてくれる人には、事前に感謝します!ContextMenuでEditTextを作成するにはどうすればいいですか
0
A
答えて
0
コンテキストメニューを使用する必要はありません。 AlertDialogを使用することができます。 ここでこの回答を確認してください。
https://stackoverflow.com/a/45352961/8200290
編集ビューで別のレイアウトを作成するだけです。
ここはあなたのソリューションです。
アプリケーションに合わせて編集する必要があります。
MainActivityクラス
public class MainActivity extends AppCompatActivity {
List<String> list = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list.add("Android");
list.add("iPhone");
list.add("Windows");
list.add("Blackberry");
list.add("Mac");
list.add("Laptop");
list.add("LCD");
list.add("Dell");
ArrayAdapter adapter = new ArrayAdapter<String>(MainActivity.this, R.layout.list_view_item, list);
ListView listView = (ListView) findViewById(R.id.mobile_list);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(MainActivity.this, "Clicked: " + list.get(position), Toast.LENGTH_SHORT).show();
AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);
View alertView = getLayoutInflater().inflate(R.layout.custom_alert, null);
//Set the view
alert.setView(alertView);
//Show alert
final AlertDialog alertDialog = alert.show();
//Can not close the alert by touching outside.
alertDialog.setCancelable(false);
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//Set the edit text for the item clicked
EditText editText = (EditText) alertView.findViewById(R.id.editText);
editText.setText(list.get(position));
ImageView closeButton = (ImageView) alertView.findViewById(R.id.closeButton);
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
});
}
});
listView.setAdapter(adapter);
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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.vzw.www.listviewalert.MainActivity">
<ListView
android:id="@+id/mobile_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
list_view_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:textSize="16dip"
android:textStyle="bold" >
</TextView>
custom_alert.xml
- >これはあなたのEDITのテキストが表示されます。一番下のボックスが描画可能/ custom_alert_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#ffffff"/>
<corners
android:radius="5dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
@警告
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/alertContainer"
android:background="@drawable/custom_alert_bg">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/rowOne">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText"/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RelativeLayout>
<ImageView
android:id="@+id/closeButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_weight="0.33"
android:background="#cdcdcd" />
</RelativeLayout>
を閉じて次のGET:
関連する問題
- 1. TabControl ContextMenuコマンドをバインドするにはどうすればいいですか?
- 2. contextMenuを縮小するにはどうすればよいですか?
- 3. TextViewとEditTextのようなWhatsappを作成するにはどうすればよいですか?
- 4. 合成WMを作成するにはどうすればいいですか?
- 5. EditTextからintを返すにはどうすればいいですか? (Android)
- 6. Railsでフィールドを作成するにはどうすればいいですか?
- 7. WordPressでフォルダを作成するにはどうすればいいですか?
- 8. VBAでリストを作成するにはどうすればいいですか?
- 9. C#でBHOを作成するにはどうすればいいですか?
- 10. Wordpressでポップアップブログコンテンツを作成するにはどうすればいいですか
- 11. tkinterでポップアップウィンドウを作成するにはどうすればいいですか?
- 12. コンテンツでフッタープッシュを作成するにはどうすればいいですか?
- 13. C#でテンプレートシステムを作成するにはどうすればいいですか
- 14. sqliteでマテリアライズドビューを作成するにはどうすればいいですか?
- 15. WPFでビジュアルラッパーを作成するにはどうすればいいですか?
- 16. Sequelizeでフィールドを作成するにはどうすればいいですか?
- 17. ListViewでセクションヘッダーを作成するにはどうすればいいですか?
- 18. Windowsでカスタムログインページを作成するにはどうすればいいですか?
- 19. ブラックベリーアプリケーションでメッセンジャーテキストボックスを作成するにはどうすればいいですか?
- 20. appengineでカウントダウンタイマーを作成するにはどうすればいいですか?
- 21. QtGuiでハイパーリンクテキストを作成するにはどうすればいいですか?
- 22. アンドロイドスタジオでスコアボードを作成するにはどうすればいいですか?
- 23. カスタムシェイプでUIViewを作成するにはどうすればいいですか?
- 24. ダウンロードボタンでポップアップを作成するにはどうすればいいですか?
- 25. Javaでカスタムソケットを作成するにはどうすればいいですか?
- 26. CEGUIでレイアウトシステムを作成するにはどうすればいいですか?
- 27. SpriteKitでコードを作成するにはどうすればいいですか?
- 28. テンプレートでデータを作成するにはどうすればいいですか?
- 29. GraphXでGraphを作成するにはどうすればいいですか
- 30. Edittextをチェックボックスに追加するにはどうすればよいですか?
私はその中のリストビューでalertdialogを作成したくありません。アイテムの1つが押されたときにalertdialogを開くlistviewを作りたいと思います。 – Keith
私は何を投稿するかは関係ありません。私はカスタムAlertDialogを作成する方法を示しています。あなたがしなければならないことは、リスト内の項目をクリックするときにこの概念を使用することだけです。アラートのためのレイアウトを編集するだけです...ここではかなりシンプルなものです。 – DroiDev