0

我正在使用 aListViewSimpleCursorAdapter显示我的 DB-Entries。到目前为止它工作正常:

public void LoadListView(){
    Cursor mCursor = mDbHelper.fetchAllFahrtenbuch();
    if (mCursor != null){     
        startManagingCursor(mCursor);
        mCursor.moveToFirst();
        ListAdapter adapter = new SimpleCursorAdapter(this,
                R.layout.fahrten_anzeigen_list_view, 
                mCursor,
                new String[] { "_id", mCursor.getColumnName(6), mCursor.getColumnName(1), mCursor.getColumnName(14), mCursor.getColumnName(15), mCursor.getColumnName(16), mCursor.getColumnName(17), mCursor.getColumnName(20)},
                new int[] { R.id.textView15, R.id.textView1, R.id.TextView3, R.id.textView5, R.id.textView6, R.id.textView9, R.id.textView10, R.id.textView13});
        setListAdapter(adapter);
        registerForContextMenu(getListView());              
        }
}

如果在条目中收到特殊值,我想要做的是删除条目。如果 的值为mCursor.getColumnName(6)0 我想删除.ListView

那可能吗?
我怎样才能做到这一点?

4

5 回答 5

4

干得好。

textView.setPaintFlags(textView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
于 2012-06-16T06:18:27.550 回答
2

在您的适配器上设置 aSimpleCursorAdapter.ViewBinder并查看是否该绑定第 6 列的数据。如果您在该列并且它具有所需的值,则删除该条目:

adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {

     public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
          if (view.getId() == R.id.textView6) {
              TextView tv = (TextView) view;
              // bind the text to this TextView(I assume that it's a TextView)
              tv.setText(cursor.getString(cursor.getColumnIndex(columnIndex))); 
              // check if it is the special value.
              // if it is strike through this entry, whatever that means
              return true;
          }
          return false;
     }

});
setListAdapter(adapter);
于 2012-06-16T06:17:12.337 回答
0

<strike>在文本中使用 html 标签

<strike>This is a line</strike> 

这是一条线

public void LoadListView(){
    Cursor mCursor = mDbHelper.fetchAllFahrtenbuch();
    if (mCursor != null){     
        startManagingCursor(mCursor);
        mCursor.moveToFirst();
        String data  = new String[] { "_id", mCursor.getColumnName(6), mCursor.getColumnName(1), mCursor.getColumnName(14), mCursor.getColumnName(15), mCursor.getColumnName(16), mCursor.getColumnName(17), mCursor.getColumnName(20);
        if (mCursor.getColumnName(6).equals("0") {
           data =  new String[] { "_id", "<strike>"+mCursor.getColumnName(6)+"</strike>", "<strike>"+mCursor.getColumnName(1)+"</strike>", "<strike>"+mCursor.getColumnName(14)+"</strike>", "<strike>"+mCursor.getColumnName(15)+"</strike>", "<strike>"+mCursor.getColumnName(16)+"</strike>", "<strike>"+mCursor.getColumnName(17)+"</strike>", "<strike>"+mCursor.getColumnName(20)+"</strike>";
        }
    ListAdapter adapter = new SimpleCursorAdapter(this,
            R.layout.fahrten_anzeigen_list_view, 
            mCursor,
            data},
            new int[] { R.id.textView15, R.id.textView1, R.id.TextView3, R.id.textView5, R.id.textView6, R.id.textView9, R.id.textView10, R.id.textView13});
    setListAdapter(adapter);
    registerForContextMenu(getListView());              
    }

}

于 2012-06-16T06:11:05.660 回答
0

是的,你可以为此你需要为listview制作custome daapter,其中在检查你的删除条件后的getView()方法中你可以将第一个文本设置为你的textview,然后使用那个textview,比如

 yourtextview.setPaintFlags(yourtextview.getPaintFlags()|Paint.STRIKE_THRU_TEXT_FLAG);
于 2012-06-16T06:20:19.037 回答
0

你可以在你的getView

    if (strikethroughState[position] == 1) {            // your if condition
        first.setPaintFlags(first.getPaintFlags()      // set strikethrough on TextView1
                | Paint.STRIKE_THRU_TEXT_FLAG);
        second.setPaintFlags(second.getPaintFlags()
                | Paint.STRIKE_THRU_TEXT_FLAG);
        third.setPaintFlags(third.getPaintFlags()
                | Paint.STRIKE_THRU_TEXT_FLAG);
        fourth.setPaintFlags(third.getPaintFlags()
                | Paint.STRIKE_THRU_TEXT_FLAG);
    }
于 2012-06-16T06:21:33.650 回答