在我的awakeFromNib
中,我使用main activity
点击按钮时显示dialog
,listview
包含三个listview
,一个textview
,一个完成edittext
。通过点击已完成的button
我只显示button
中edittext
中使用linear layout
中main activity
中的值的行,现在我想要的是当我再次重新打开dialog
列表时,edittext
字段将包含之前已添加的值。我怎么能这样做?
这是填充listview
,
dialog
的代码
allProducts = dh.gettAllProductInfo();
adapter = new ProductListAdapter(getApplicationContext(), allProductss);
productListView.setAdapter(adapter);
这就是点击完成button
...
doneButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ArrayList<productinfo> AddedItems = new ArrayList<productinfo>();
try
{
for(int i = 0;i<allProductss.size();i++)
{
View view = productListView.getChildAt(i);
EditText qty = (EditText) view.findViewById(R.id.quantity_edittext);
String qtyVal = qty.getText().toString();
TextView product = (TextView) view.findViewById(R.id.product_textview);
String pName = product.getText().toString();
TextView p_code = (TextView) view.findViewById(R.id.product_code);
String pCode = p_code.getText().toString();
if(qty.getText().toString().matches(""))
{
//Do nothing
}
else
{
AddedItems.add(new productinfo(pCode, pName, "", qtyVal, ""));
}
}
答案 0 :(得分:0)
我试着根据我理解你想要的东西做一个例子。此外,您需要使其适应您的代码工作。这是一个例子:
private ArrayList<productinfo> AddedItems;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// you have to put this part of code when you show the dialog so that
// it will be executed all the time you open the dialog
if(AddedItems != null){
allProducts.addAll(AddedItems);
AddedItems = null;
}
else{
allProducts = dh.gettAllProductInfo();
}
adapter = new ProductListAdapter(getApplicationContext(), allProductss);
productListView.setAdapter(adapter);
doneButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AddedItems = new ArrayList<productinfo>();
try
{
for(int i = 0;i<allProductss.size();i++)
{
View view = productListView.getChildAt(i);
EditText qty = (EditText) view.findViewById(R.id.quantity_edittext);
String qtyVal = qty.getText().toString();
TextView product = (TextView) view.findViewById(R.id.product_textview);
String pName = product.getText().toString();
TextView p_code = (TextView) view.findViewById(R.id.product_code);
String pCode = p_code.getText().toString();
if(!qty.getText().toString().matches(""))
{
AddedItems.add(new productinfo(pCode, pName, "", qtyVal, ""));
}
}
}
catch(Exception e){}
}
}
}