English 中文(简体)
简言之:在《海关清单》中确定单个纽芬兰语的可见度
原标题:Android : set visibility of individual buttons in a custom ListView

我有一份清单,有一份定制调制人(来自基地Adapter),各行的布局包括一个文本电文和一个布顿。 在名单编制之后,我想改变具体县的可见度。

为此,我需要从方案上了解个人行情。 我无法找到如何做到这一点。 提到有意见(立场),但我看不到这种方法;getView(需要3个参数。 我作为<条码>通过的内容 观点(立场) 观点改变 观点,小组的上级:?

Could you please point me in right direction?

UPDATE: The View received by v = myListView.getChildAt (myListView.getFirstVisiblePosition ();. 另外,我的ListView.getChildCount()正在返回。

问题回答

Here is an example I of a custom adapter I used in a list view in which the user can select items in the listView and mark them for Delete. The key is to add the onClickListener after you have a view. Then you can use that to not only change the view, but update the data of the adapter too. Hopefully you can modify this code to suit your particulars.

private class DeletePlayerAdapter extends ArrayAdapter<Player> {
    Context context;
    int layoutResourceId;
    ArrayList<Player> data;

    public DeletePlayerAdapter(Context context, int layout,
            ArrayList<Player> list) {
        super(context, layout, list);
        this.layoutResourceId = layout;
        this.context = context;
        this.data = list;
    }

    @Override
    public View getView(final int position, View convertView,
            ViewGroup parent) {
        View row = convertView;
        PlayerHolder holder = null;
        if (row == null) {
            LayoutInflater inflater = ((Activity) context)
                    .getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);
            holder = new PlayerHolder();
            holder.player_name = (TextView) row
                    .findViewById(R.id.player_name);
            holder.player_number = (TextView) row
                    .findViewById(R.id.player_number);
            holder.seeded_button = (ImageButton) row
                    .findViewById(R.id.delete_toggle);
            holder.player_name.setTypeface(tf);
            holder.player_number.setTypeface(tf);
            row.setTag(holder);
            players_array.get(position).marked_for_delete = false;

        } else {
            Log.d("PLAYER_ADAPTER", "NOT_NULL ROW");
            holder = (PlayerHolder) row.getTag();
        }
        holder.seeded_button.setOnClickListener(new OnClickListener() {
            private int pos = position;

            public void onClick(View v) {
                ImageButton b = (ImageButton) v;
                if (b.isSelected()) {
                    b.setSelected(false);
                    players_array.get(pos).marked_for_delete = false;
                } else {
                    b.setSelected(true);
                    players_array.get(pos).marked_for_delete = true;
                }
            }
        });
        Player p = data.get(position);
        holder.player_name.setText(p.name);
        holder.player_number.setText(String.valueOf(position+1));
        holder.seeded_button
                .setSelected(players_array.get(position).marked_for_delete);
        return row;
    }

}

static class PlayerHolder {
    TextView player_number;
    TextView player_name;
    ImageButton seeded_button;
}




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签