[英]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.