如何在android中创建可扩展布局?

发布于 2024-11-04 17:45:46 字数 144 浏览 0 评论 0原文

任何人都可以帮助我创建一个可扩展的视图,如 android 市场中的更多按钮吗? 当我们点击“更多”按钮时,它将扩展视图,其中包含有关 Android 市场中应用程序的更多详细信息。

任何帮助将不胜感激。

谢谢

sathish

Can any one help me to create an expandable view like more button in android market?
when we click on more button it will expand the view with more details about the application in android market place..

Any help will be greatly appreciated..

thanks

sathish

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

迷离° 2024-11-11 17:45:47

我一直在做类似的事情。

目前,在 more/less 栏模式下,它看起来像这样:more/less 视图布局

它仍在进行中,但可以在此处查看项目和源代码

I have been working on something similar.

At the moment it looks like this in the more/less bar mode:more/less view layout

It is still a work in progress but the project and source can be viewed here

失眠症患者 2024-11-11 17:45:47

也许实现这一点的最佳方法是使用 ArrayAdapter。当您单击“更多”按钮时,获取更多数据并使用 addAll() 方法将所有新获取的数据添加到适配器。 addAll() 会自动将更改传播到 ListView,因此无需显式通知它。

Maybe the best way to implement this is to use ArrayAdapter. When you click on More button fetch more data and use addAll() method to add all newly fetched data to the adapter. addAll() automatically will propagate changes to the ListView so don't bother to notify it explicit.

拥抱我好吗 2024-11-11 17:45:47
public class ModifiedExpandableList extends Activity {

    ExpandableListAdapter mAdapter;
    private ExpandableListView mExpandableListView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_copy);
        // set our list
        mExpandableListView = (ExpandableListView)findViewById(R.id.list);
        // Set up our adapter
        mAdapter = new MyExpandableListAdapter(this);
        mExpandableListView.setAdapter(mAdapter);
        // Need no icon as of now
        mExpandableListView.setGroupIndicator(null);
        registerForContextMenu(mExpandableListView);
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
        menu.setHeaderTitle("Sample menu");
        menu.add(0, 0, 0,"dd");
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();

        String title = ((TextView) info.targetView).getText().toString();

        int type = ExpandableListView.getPackedPositionType(info.packedPosition);
        if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
            int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition); 
            int childPos = ExpandableListView.getPackedPositionChild(info.packedPosition); 
            Toast.makeText(this, title + ": Child " + childPos + " clicked in group " + groupPos,
                    Toast.LENGTH_SHORT).show();
            return true;
        } else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
            int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition); 
            Toast.makeText(this, title + ": Group " + groupPos + " clicked", Toast.LENGTH_SHORT).show();
            return true;
        }

        return false;
    }

    /**
     * A simple adapter which maintains an ArrayList of photo resource Ids. 
     * Each photo is displayed as an image. This adapter supports clearing the
     * list of photos and adding a new photo.
     *
     */
    public class MyExpandableListAdapter extends BaseExpandableListAdapter {

        Context mContext;
        public MyExpandableListAdapter(Context context){
            this.mContext = context;
        }

        // Sample data set.  children[i] contains the children (String[]) for groups[i].
        private String[] groups = { "People Names", "Dog Names", "Cat Names", "Fish Names" };
        private String[][] children = {
                { "Arnold", "Barry", "Chuck", "David" },
                { "Ace", "Bandit", "Cha-Cha", "Deuce" },
                { "Fluffy", "Snuggles","ddef","afadsfasf" },
                { "Goldy", "Bubbles","sfef","dafs" }
        };

        public Object getChild(int groupPosition, int childPosition) {
            return children[groupPosition][childPosition];
        }

        public long getChildId(int groupPosition, int childPosition) {
            return childPosition;
        }

        public int getChildrenCount(int groupPosition) {
            int result=4;

            return result;
       }

        public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
                View convertView, ViewGroup parent) {
            View v = null;
            // changed here
                LayoutInflater li = ModifiedExpandableList.this.getLayoutInflater();
                v = li.inflate(R.layout.child_view,null);
                TextView tv = (TextView)v.findViewById(R.id.TextView01);
                tv.setText(getChild(groupPosition, childPosition).toString());
                ImageView im = (ImageView)v.findViewById(R.id.ImageView01);
                im.setBackgroundDrawable(ModifiedExpandableList.this.getResources().getDrawable(R.drawable.closearrow));
            return v;
        }

        public Object getGroup(int groupPosition) {
            return groups[groupPosition];
        }

        public int getGroupCount() {
            return groups.length;
        }

        public long getGroupId(int groupPosition) {
            return groupPosition;
        }

        public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
                ViewGroup parent) {
            // change here to modify parent group layout
            View v = null;
            LayoutInflater li = ModifiedExpandableList.this.getLayoutInflater();
            v = li.inflate(R.layout.parent_view,null);
            TextView tv = (TextView)v.findViewById(R.id.TextView01);
            tv.setText(getGroup(groupPosition).toString());
            ImageView im = (ImageView)v.findViewById(R.id.ImageView01);
            im.setBackgroundDrawable(ModifiedExpandableList.this.getResources().getDrawable(R.drawable.closearrow));
            if(isExpanded){
                im.setBackgroundDrawable(ModifiedExpandableList.this.getResources().getDrawable(R.drawable.closearrow_b));
            }
            return v;
        }

        public boolean isChildSelectable(int groupPosition, int childPosition) {
            return true;
        }

        public boolean hasStableIds() {
            return true;
        }

    }
}
public class ModifiedExpandableList extends Activity {

    ExpandableListAdapter mAdapter;
    private ExpandableListView mExpandableListView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_copy);
        // set our list
        mExpandableListView = (ExpandableListView)findViewById(R.id.list);
        // Set up our adapter
        mAdapter = new MyExpandableListAdapter(this);
        mExpandableListView.setAdapter(mAdapter);
        // Need no icon as of now
        mExpandableListView.setGroupIndicator(null);
        registerForContextMenu(mExpandableListView);
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
        menu.setHeaderTitle("Sample menu");
        menu.add(0, 0, 0,"dd");
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();

        String title = ((TextView) info.targetView).getText().toString();

        int type = ExpandableListView.getPackedPositionType(info.packedPosition);
        if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
            int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition); 
            int childPos = ExpandableListView.getPackedPositionChild(info.packedPosition); 
            Toast.makeText(this, title + ": Child " + childPos + " clicked in group " + groupPos,
                    Toast.LENGTH_SHORT).show();
            return true;
        } else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
            int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition); 
            Toast.makeText(this, title + ": Group " + groupPos + " clicked", Toast.LENGTH_SHORT).show();
            return true;
        }

        return false;
    }

    /**
     * A simple adapter which maintains an ArrayList of photo resource Ids. 
     * Each photo is displayed as an image. This adapter supports clearing the
     * list of photos and adding a new photo.
     *
     */
    public class MyExpandableListAdapter extends BaseExpandableListAdapter {

        Context mContext;
        public MyExpandableListAdapter(Context context){
            this.mContext = context;
        }

        // Sample data set.  children[i] contains the children (String[]) for groups[i].
        private String[] groups = { "People Names", "Dog Names", "Cat Names", "Fish Names" };
        private String[][] children = {
                { "Arnold", "Barry", "Chuck", "David" },
                { "Ace", "Bandit", "Cha-Cha", "Deuce" },
                { "Fluffy", "Snuggles","ddef","afadsfasf" },
                { "Goldy", "Bubbles","sfef","dafs" }
        };

        public Object getChild(int groupPosition, int childPosition) {
            return children[groupPosition][childPosition];
        }

        public long getChildId(int groupPosition, int childPosition) {
            return childPosition;
        }

        public int getChildrenCount(int groupPosition) {
            int result=4;

            return result;
       }

        public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
                View convertView, ViewGroup parent) {
            View v = null;
            // changed here
                LayoutInflater li = ModifiedExpandableList.this.getLayoutInflater();
                v = li.inflate(R.layout.child_view,null);
                TextView tv = (TextView)v.findViewById(R.id.TextView01);
                tv.setText(getChild(groupPosition, childPosition).toString());
                ImageView im = (ImageView)v.findViewById(R.id.ImageView01);
                im.setBackgroundDrawable(ModifiedExpandableList.this.getResources().getDrawable(R.drawable.closearrow));
            return v;
        }

        public Object getGroup(int groupPosition) {
            return groups[groupPosition];
        }

        public int getGroupCount() {
            return groups.length;
        }

        public long getGroupId(int groupPosition) {
            return groupPosition;
        }

        public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
                ViewGroup parent) {
            // change here to modify parent group layout
            View v = null;
            LayoutInflater li = ModifiedExpandableList.this.getLayoutInflater();
            v = li.inflate(R.layout.parent_view,null);
            TextView tv = (TextView)v.findViewById(R.id.TextView01);
            tv.setText(getGroup(groupPosition).toString());
            ImageView im = (ImageView)v.findViewById(R.id.ImageView01);
            im.setBackgroundDrawable(ModifiedExpandableList.this.getResources().getDrawable(R.drawable.closearrow));
            if(isExpanded){
                im.setBackgroundDrawable(ModifiedExpandableList.this.getResources().getDrawable(R.drawable.closearrow_b));
            }
            return v;
        }

        public boolean isChildSelectable(int groupPosition, int childPosition) {
            return true;
        }

        public boolean hasStableIds() {
            return true;
        }

    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文