如何一个EditText添加到ListView

如何一个EditText添加到ListView

本文介绍了如何一个EditText添加到ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待读取从数据库中的一些产品的细节,然后将它们添加到ListView。

I'm looking to read some product details in from a database and then add them to a ListView.

我想,然后在每行数量的EditText框,用户可以在添加数量。
我怎样才能做到这一点?我做了一个简单的页面,但是当我回来了输入数量和向下滚动,然后我松散的数据,或者甚至会出现在另一行的另一个数量框。

I then want on each line a qty EditText box where customer can add a qty in.How can I do this? I did a simple page but when I enter a qty and the scroll down and then back up again I loose the data or it even appears in another qty box on another row.

推荐答案

好吧,你需要做的第一件事是创建要在列表中的每一行有布局的Row.xml文件..

Okay so the first thing you will need to do is create a Row.xml file for the layout that you want each row in the list to have..

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
 android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/icon"
android:padding="2dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ok"
/>
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"
/>
//Add a edittext here..
/LinearLayout>

接下来,您将需要扩展ListView和覆盖得到鉴于您的自定义行加载。

Next you will need to extends listview and override get view to load in your custom row.

public class Demo extends ListActivity {

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
setListAdapter(new Adapter());}

//Here extends a ArrayAdapter to create your custom view
class Adapter extends ArrayAdapter<String> {
Adapter() {
super(DynamicDemo.this, R.layout.row, R.id.label, items);
}
public View getView(int position, View convertView,
ViewGroup parent) {
//Here load in your views such as the edittext

}

这就是你需要开始你就可以调用onItemListClick()来获取每一个当用户点击该项目点击。

Thats what you will need to get started you can then call onItemListClick() to get each click when the user clicks the item.

您可以在这里得到一个完整的教程...

You can get a full tutorial here...

编辑:

此外,如果你想保存在数量框中的数字,你需要有一个包。

    saveState和()方法

Also if you want to save the number in the quantity box you will need to have a Bundle.Such as saveState() method

这将节省您的用户数量数而应用程序仍然活着,并带回眼帘时拉号码或从包诠释。

This will save your users quantity number while the app is still alive, and when brought back into view pull the number or int from the bundle.

这应该是帮助

这篇关于如何一个EditText添加到ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 01:29