简体   繁体   English

使用我的editText,我想从数组列表中查看保存的项目列表,并显示有关该项目的几行详细信息

[英]using my editText i want to see saved list of items from my arraylist and display a couple of lines of detail about the item

i have EditText and two buttons(SAVE & EDIT). 我有EditText和两个按钮(保存和编辑)。 how do i use the edittext to list a list of item which i want to create in a ArrayList. 我如何使用edittext列出要在ArrayList中创建的项目列表。 the edittext will give me the stored items, save button will give me the opportunity to save any item i want to save in the array and edit button will give me the opportunity to update existing item. edittext将为我提供存储的项目,保存按钮将使我有机会保存要保存在数组中的任何项目,而编辑按钮将使我有机会更新现有项目。 thanks a lot for your effort. 非常感谢您的努力。 here is the MainActivity code.. 这是MainActivity代码。

Button btnSave, btnEdit; 按钮btnSave,btnEdit;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btnSave= (Button) findViewById(R.id.buttonSave);
    btnEdit= (Button) findViewById(R.id.buttonEdit);

    btnSave.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent= new Intent(MainActivity.this, InsertItem.class);
            startActivity(intent);
        }
    });

    btnEdit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent= new Intent(MainActivity.this, UpdateItem.class);
            startActivity(intent);
        }
    });

}

} }

This is updateActivity.. 这是updateActivity ..

Button btnUpdate;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    setContentView(R.layout.activity_update_item);


    btnUpdate=findViewById(R.id.buttonUpdate);
    btnUpdate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(UpdateItem.this,"Update Item",Toast.LENGTH_LONG).show();
        }
    });
}

} }

SaveActivity code.... SaveActivity代码...。

Button btnApply; 按钮btnApply;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    setContentView(R.layout.activity_insert_item);




    btnApply= findViewById(R.id.buttonApply);
    btnApply.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(InsertItem.this,"Item Inserted",Toast.LENGTH_LONG).show();
        }
    });
}

} }

I'm not exactly sure what do you mean by saying "use the EditText to list a list of items", but you're probably looking for AutoCompleteTextView , where you can set your array of items in an adapter and then display them in a list form. 我不确定要说“使用EditText列出项目列表”是什么意思,但是您可能正在寻找AutoCompleteTextView ,您可以在其中设置项目数组,然后在适配器中显示它们。列表形式。

You can then modify the ArrayList by putting a new item or getting the item you want to edit by using OnItemClickListener . 然后,您可以通过放置新项或使用OnItemClickListener获得要编辑的项来修改ArrayList

EDIT: 编辑:

For inserting an item 用于插入项目

btnSave.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            arrayList.add(valueFromEditText); // add element to arrayList
            adapter.notifyDataSetChanged(); // refresh the adapter
        }
    });

Hope I could help you somehow :) 希望我能以某种方式帮助您:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想使用ArrayList从数据库中显示控制台中的所有数据 - I want to display all the data in my console from the data base using ArrayList 我的Recycleview显示列表和完整列表仅间歇地显示我添加到ArrayList的最后一项 - My Recycleview display list and complete list only intermittently displays the last item I add to my ArrayList 我想在 recyclerview 中显示来自 arraylist 的相同项目 - I want to display same items from arraylist in recyclerview 当我使用removeAll(和e.getValueIsAdjusting == false)从列表中删除多个项目时,为什么ListSelectionListener会看到多个事件? - Why does my ListSelectionListener see multiple events when I delete multiple items from a list using removeAll ( and e.getValueIsAdjusting == false)? 如何在列表视图中显示使用Filewriter保存的项目 - how do i display an item saved using filewriter in a list view 通过单击 TextView 我想查看项目列表 - by clicking on TextView i want to see the list of items 如何从另一个类的ArrayList中获取一项并在当前类的ArrayList中引用它(仅使用索引)? - How do I get an item from an ArrayList in another class and reference it in an ArrayList in my current class (using only indexes)? 我想使用 ArrayList 在不同的行中显示我的 output - I would like to display my output in an different line using ArrayList 如何显示 arraylist 中的元素? - How do I display the elements from my arraylist? 如果我想存储来自多行输入的数据,最好使用Arraylist吗? - If i want to store data from an input with multiple lines am i best using an Arraylist?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM