编辑文本文本已更改以避免重复

时间:2016-03-21 09:24:47

标签: android listview android-edittext android-cursoradapter textwatcher

使用游标适配器创建列表视图时,列表视图中的编辑文本会获得重复值。我不知道在我的编辑文本中写入文本更改方法的内容。请帮忙.. 下面显示的是我在类列表中查看数据的类,这是从我的on create methode

调用的
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.orders);
    list = (ListView)findViewById(R.id.list);
     this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
     databas.clear();



    curserdata();
}
private void curserdata() {
    DatabaseHelper dbHelper = new DatabaseHelper(this.getApplicationContext());
    newDB = dbHelper.getWritableDatabase();
    Cursor c = dbHelper.DataP();

      // The desired columns to be bound
      String[] columns = new String[] {
              dbHelper.name,
              dbHelper.mail,
              dbHelper.num,

      };

      // the XML defined views which the data will be bound to
      int[] to = new int[] { 
        R.id.name,
        R.id.mail,
        R.id.num,

      };

      // create the adapter using the cursor pointing to the desired data 
      //as well as the layout information
      dataAdapter = new SimpleCursorAdapter(
        this, R.layout.list_simple_row, c, columns, to,0);

      // Assign adapter to ListView
      list.setAdapter(dataAdapter);


       EditText text = (EditText) findViewById(R.id.addrs);
      text.addTextChangedListener(new TextWatcher() {

       public void afterTextChanged(Editable s) {
       }

       public void beforeTextChanged(CharSequence s, int start, 
         int count, int after) {
       }

       public void onTextChanged(CharSequence s, int start, 
         int before, int count) {
        //dataAdapter.getFilter().filter(s.toString());
       }
      });



     }

这是我的list_simple_row.xml

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:shrinkColumns="*"
android:stretchColumns="*" 
android:layout_margin="4dp"
 >



<TableRow
    android:id="@+id/tableRow6"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >

    <TextView
        android:id="@+id/name"
        android:layout_height="70dp"
        android:text=""
          android:gravity="center"
         android:layout_span="4"

        >
    </TextView>
 <TextView
        android:id="@+id/mail"
        android:text=""
        android:gravity="center_horizontal"
         android:layout_span="4"
        >
    </TextView>
  <EditText
        android:id="@+id/num"
       android:inputType="number"
         android:text=""
        android:gravity="center_horizontal"
         android:layout_span="4"
         >
    </EditText>
  <EditText
        android:id="@+id/addrs"
         android:gravity="center_horizontal"
         android:inputType="number"
         android:text=""
         android:layout_span="4">
        </EditText>
             </TableRow>
</TableLayout>

0 个答案:

没有答案