0

My idea is to do a shopping list and when i click on an item it gets a strikethrough and goes to the end of the list. So far i have gotten everything except sending the item to the end of the list. Here is a bit of my code:

protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);

    TextView text = (TextView) v.findViewById(android.R.id.text1);
    text.setPaintFlags(text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

}

Edit:

Thank you for the anwsers so far. Some helpful people requested more code so here is everything (including adding stuff to list):

public class ShoppingActivity extends ListActivity {

    ArrayList<String> list = new ArrayList<String>();
    ArrayAdapter<String> adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shopping);

        Button add = (Button) findViewById(R.id.btnAdd);

        adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, list);

        OnClickListener listner = new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                EditText item = (EditText) findViewById(R.id.etItem);
                list.add(item.getText().toString());
                item.setText("");
                adapter.notifyDataSetChanged();
            }
        };

        add.setOnClickListener(listner);

        setListAdapter(adapter);
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        // TODO Auto-generated method stub
        super.onListItemClick(l, v, position, id);

        TextView text = (TextView) v.findViewById(android.R.id.text1);
        text.setPaintFlags(text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

    }
}
4

2 回答 2

1

Your adapter tells the list what order items are in. Make the adapter tell it that this item is at the end- probably by removing it from the ArrayList its in and adding it to the end of the list, but the exact method depends on your code. Then tell the adapter that its data has changed by calling notifyDataSetChanged.

于 2013-01-16T22:01:06.727 回答
-1

first get the list long. Once you have it, you only set the item strikethrough position to the list long, this will put your item as the bottom

于 2013-01-16T21:57:01.757 回答