Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created August 2, 2022 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeforfun-jp/e4cf1b790762a869b42e06b27c9aa7b8 to your computer and use it in GitHub Desktop.
Save codeforfun-jp/e4cf1b790762a869b42e06b27c9aa7b8 to your computer and use it in GitHub Desktop.
【Java】ListView with two textview 4
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/* 省略 */
// クリックイベント
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
// 新しい項目を追加
Map<String, String> item = new HashMap<>();
item.put("name", "いぬ");
item.put("detail","「いぬ」の説明文が入ります。");
listData.add(item);
// クリックした項目を削除
listData.remove(i);
// 変更を反映させる
adapter.notifyDataSetChanged();
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment