0

我是新来的android和我正在从事小任务。我遇到了一些问题,我真的需要帮助。如何从listview中获取edittext项目?

我有一个自定义列表视图,其中包含一个textview,一个edittext,再次一个textview和下面,我有一个按钮。我的问题是,当我点击该按钮时,我需要从所有列表项中获取edittext值。

我不知道如何做到这一点,所以我恳请大家帮助我解决这个问题。 下面是我用于自定义listview的代码。

public class MyAdapter extends ArrayAdapter<String> { 

    private final Context context; 
    private final String[] items; 

    public MyAdapter(Context context, String[] items) { 
     super(context, R.layout.list_row, items); 
     this.context = context; 
     this.items = items; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     View rowView = inflater.inflate(R.layout.list_row, parent, false); 
     TextView textView = (TextView) rowView.findViewById(R.id.text_Product); 
     TextView textPrice = (TextView)rowView.findViewById(R.id.text_Price); 
     EditText edit_Quantity = (EditText)rowView.findViewById(R.id.edit_Quantity); 
     textView.setText(items[position]); 

     String s = items[position]; 

     if (s.equals("Samsung")) { 
      textPrice.setText("10000"); 
      edit_Quantity.setText("0"); 
     } else if (s.equals("Apple")) { 
      textPrice.setText("15000"); 
      edit_Quantity.setText("1"); 
     } else if (s.equals("Nokia")) { 
      textPrice.setText("8000"); 
      edit_Quantity.setText("2"); 
     } else { 
      textPrice.setText("12000"); 
      edit_Quantity.setText("3"); 
     } 
     return rowView; 
    } 
} 

我需要edittext值存储在列表中,当我点击按钮。请帮我这个

在此先感谢。

+0

使用此链接:http://stackoverflow.com/questions/ 14908670 /如何对节目 - 值的-的EditText功能于列表视图,每个时间启动按钮点击功能于安卓 – Lokesh

回答

1

只是在你的代码中添加列表像

List <String> editcontent= new ArrayList<String>(); 

,现在当你书面方式项目到编辑文本。 也使列表视图中的条目

editcontent.add(0); .// for samsung (ref. to your code) 

if (s.equals("Samsung")) { 
      textPrice.setText("10000"); 
      edit_Quantity.setText("0"); 
      editcontent.add(0); 
     } else if (s.equals("Apple")) { 
      textPrice.setText("15000"); 
      edit_Quantity.setText("1"); 
      editcontent.add(1); 
     } else if (s.equals("Nokia")) { 
      textPrice.setText("8000"); 
      edit_Quantity.setText("2"); 
      editcontent.add(2); 
     } else { 
      textPrice.setText("12000"); 
      edit_Quantity.setText("3"); 
      editcontent.add(3); 
     } 

,那么你可以从该列表获取你想要的记录 例如:

editcontent.get(position); 
相关问题