1

我有ListView一个onClicklListener

ListView一排Layout/res/listitem_a

现在在onClickevent任何列表项之后,我只想更改该列表项的布局以说/res/listitem_b..

关于我将如何进行的任何帮助。

4

2 回答 2

0

使用 BaseAdapter 并在 getView 调用中进行修改。

public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.custom_layout, null);
            // Creates a ViewHolder and store references to the two children views
            // we want to bind data to.
            holder = new ViewHolder();
            holder.text = (TextView) convertView.findViewById(R.id.text);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        // Change text size
        holder.text.setTextAppearance(context,R.style.customStyle);

        return convertView;
    }

    static class ViewHolder {
        TextView text;
    }

您可以在getView 调用中使用位置变量来更改特定行。希望这有帮助!!!

于 2012-10-27T12:17:10.687 回答
0

您可以使用 ViewFlipper 作为行的布局。使用 ViewFlipper,您可以指定任意数量的布局,并在发生某些事情时在它们之间翻转(例如单击事件)。是一个关于 ViewFlipper 的好教程。

此外,您应该实现自定义适配器、扩展 BaseAdapter 并覆盖 getView 方法。

@Override
public View getView(int position, View view, ViewGroup parent) {
    if (view == null) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.your_row_layout, null);  //this will inflate the layout into each row
    }

    //from here on, assign the information to display to the layout widgets

希望我对你有所帮助。

于 2012-10-28T17:21:33.883 回答