1

如何像这张图片 http://imgur.com/hMSZxbp那样水平显示列表视图。我想水平显示列表视图图像和文本并动态加载列表视图。此示例http://www.androidconnect.org/2012/05/10/como-hacer-listview-horizo ​​ntales/ 从所有文本视图和所有文本视图中加载单个图像是硬编码的每个字符串的图像加载并行所有数据都是静态的

HorizontalListView listview = (HorizontalListView) findViewById(R.id.listview);
    listview.setAdapter(new HAdapter());

}

private static String[] dataObjects = new String[]{ "Text #1",
    "Text #2",
    "Text #3",
    "Text android",
    "Text connnect",
    "www.androidconnect.org"};

private class  HAdapter extends BaseAdapter {

    public HAdapter(){
        super();
    }
    private OnClickListener mOnButtonClicked = new OnClickListener() {

        public void onClick(View v) {
            Button bt = (Button) v;

            Toast.makeText(getApplicationContext(), "Hola desde " + bt.getText(),  
 Toast.LENGTH_SHORT).show();          
        }
    };


    public int getCount() {
        return dataObjects.length;
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }


    public View getView(int position, View convertView, ViewGroup parent) {
        View retval =    
    LayoutInflater.from(parent.getContext()).inflate(R.layout.viewitem, null);
        TextView title = (TextView) retval.findViewById(R.id.title);
        Button button = (Button) retval.findViewById(R.id.clickbutton);
        button.setOnClickListener(mOnButtonClicked);
        title.setText(dataObjects[position]);

        return retval;
    }

};

}
4

0 回答 0