添加Strikethrough onitemclick ListView Android

时间:2017-03-08 13:00:19

标签: android listview project onclicklistener

我有一个小项目,我被困在OnClickItem ListView

这就是我所做的

// variable declaration
private ListView mainList;
private MediaPlayer mp;
private final String[] listContent = {
        "1. menu one","2. menu two",
        "3. menu three" };

private final int[] resID = {
        R.raw.none,            R.raw.none,            R.raw.none };

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_upacarabendera);
    // Initializing variables
    mp = new MediaPlayer();
    mainList = (ListView) findViewById(R.id.listview2);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, listContent);
    mainList.setAdapter(adapter);

    mainList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view,
                                int position, long id) {
            playSong(position);
        }

    });


}

public void playSong(int songIndex) {
    // Play song
    mp.reset();// stops any current playing song
    mp = MediaPlayer.create(getApplicationContext(), resID[songIndex]);// create's
    // new
    // mediaplayer
    // with
    // song.
    // if you don't know what is getApplicationContext() here better use
    // MainActivity.this or yourclassname.this
    mp.start(); // starting mediaplayer
    // setting up what to do if current song completes.
    /*
     * mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
     *
     * @Override public void onCompletion(MediaPlayer mp) { // TODO
     * Auto-generated method stub
     *
     * } });
     */
}

@Override
public void onDestroy() {
    super.onDestroy();
    mp.release();
}

当我添加

    TextView text = (TextView) view;
 text.setPaintFlags(text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

在playSong(位置)之后,在构建apk中没有错误,但是当我点击列表视图时,它会让我发生错误崩溃。

我想要的是,当我的listView被点击时,它会被删除,等等所有项目点击后。

感谢您的帮助

0 个答案:

没有答案