列表视图以匿名方式运行

时间:2014-10-02 10:54:24

标签: java android listview android-listview listviewitem

我在列表视图上工作,我确实创建了自定义列表视图。列表视图项包含指向所选列表行,文本,分隔符行和删除按钮的箭头。首先箭头是不可见的,然后可以看到所选儿童的箭头视图。但是,当我要去看它时它没有用。我确实尝试了很多时间通过清理项目再次构建它但它没有工作,我没有得到主要问题所以需要帮助。这是我的代码。

public class MusicListadaper extends BaseAdapter {

    int previouspostion=-1;
    Activity context;
    ArrayList<Item> soundItems;
    LayoutInflater inflater;
    View Music_List_Layout,root_view;
    public TextView listview_arrow, listview_text, listview_seperator;
    boolean isDeleteButtonVisibility = false;
    MusicPlay musicPlayObj;
    PlaySounds playSounds;
    public MusicListadaper(Activity context, ArrayList<Item> listItems,
            boolean isDeleteButtonVisible, MusicPlay musicPlayObj) {
        this.context = context;
        soundItems = listItems;
        this.musicPlayObj = musicPlayObj;
        playSounds = new PlaySounds(context);
        this.isDeleteButtonVisibility = isDeleteButtonVisible;
        root_view=context.getWindow().getDecorView().findViewById(android.R.id.content);

    }

    @Override
    public int getCount() {
        return soundItems.size();
    }

    @Override
    public MusicListadaper getItem(int arg0) {
        return this;
    }

    @Override
    public long getItemId(int arg0) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        inflater = (LayoutInflater) context
                .getSystemService(context.LAYOUT_INFLATER_SERVICE);


        // Log.d("Total Postions", soundItems.size()+"");
        if (convertView == null) {
            Music_List_Layout = inflater.inflate(R.layout.listview_items, null);
            listview_arrow = (TextView) Music_List_Layout
                    .findViewById(R.id.listview_arrow);
            listview_arrow.setTag("Arrow_"+position);

            listview_text = (TextView) Music_List_Layout
                    .findViewById(R.id.listview_text);
            listview_text.setTypeface(Font.getListItemTextTypeFace());
            listview_seperator = (TextView) Music_List_Layout
                    .findViewById(R.id.listview_seperator);
            ImageView btn_delete_songs = (ImageView) Music_List_Layout
                    .findViewById(R.id.btn_delete_songs);
            View listitem_main_layout = Music_List_Layout
                    .findViewById(R.id.listitem_main_layout);
            if (!isDeleteButtonVisibility) {
                btn_delete_songs
                        .setBackgroundResource(R.drawable.btn_add_selector);
            } else {
                listitem_main_layout
                        .setBackgroundResource(R.drawable.template_musicplay_selector);
            }
            listview_arrow.setVisibility(View.INVISIBLE);
            btn_delete_songs.setTag("btn_" + position);
            listitem_main_layout.setTag("btn_" + position);
            // *******************************Implemetn click listner
            btn_delete_songs.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    String tag = (String) v.getTag();
                    String[] arr = tag.split("_");
                    GalleryMusicDbHandler dbManager = new GalleryMusicDbHandler(
                            context, new KeysString());
                    if (isDeleteButtonVisibility) {
                        try {

                            dbManager.deleteSpecificSongFromDb(soundItems
                                    .get(Integer.parseInt(arr[1])));
                            soundItems.remove(Integer.parseInt(arr[1]));

                            musicPlayObj.updateMainListSong(
                                    Integer.parseInt(arr[1]),
                                    isDeleteButtonVisibility);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    } else {

                        if (dbManager.insertGallerySong(soundItems.get(Integer
                                .parseInt(arr[1])))) {
                            Toast.makeText(context,
                                    "Congratulation Song is added",
                                    Toast.LENGTH_SHORT).show();
                        } else {
                            Toast.makeText(context,
                                    "Already added to PlayList",
                                    Toast.LENGTH_SHORT).show();
                        }
                        musicPlayObj.updateMainListSong(
                                Integer.parseInt(arr[1]),
                                isDeleteButtonVisibility);
                    }

                }
            });
            listview_text.setText(soundItems.get(position).getTitle());
            Log.d("Position", position + " "
                    + soundItems.get(position).getTitle());

            if (isDeleteButtonVisibility) {
                listitem_main_layout.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        TextView view;
                        if(previouspostion!=-1){
                            view=(TextView) root_view.findViewWithTag("Arrow_"+previouspostion);
                            view.setVisibility(View.INVISIBLE);
                        }
                        view=(TextView) root_view.findViewWithTag("Arrow_"+(KeysInteger.NUMOFMUSIC+position));
                        view.setVisibility(View.VISIBLE);
                        previouspostion=(KeysInteger.NUMOFMUSIC+position);


                    }
                });
            }

        }

        return Music_List_Layout;
    }

    public void setVisibleArrowButton() {

    }

}

以下是我的完整代码listitem_main_layout点击监听器无法正常工作我需要帮助。

1 个答案:

答案 0 :(得分:0)

调用notifydatasetchanged方法解决此问题