1

我是为 android 开发的新手,我正在尝试制作一个带有标题和副标题的 ListActivity。到目前为止,仅设法使标题:

this.data = new ArrayList<String>();

// add some objects into the array list
this.data.add("YOU WILL HEAR");
this.data.add("USEFUL PHRASES");
this.data.add("VOCABULARY");
this.data.add("DIALOGUES");
this.data.add("INFORMATION");

this.port = new ArrayList<String>();
this.port.add("BEM VINDO");
this.port.add("FRASES ÚTEIS");
this.port.add("VOCABULÁRIO");
this.port.add("DIÁLOGOS");
this.port.add("VOCABULÁRIO");

this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item,R.id.title,this.data));

ListView lv = getListView();

此代码在 onCreate 方法中。

我的问题是,我怎样才能R.id.subtitle用第二个数组填充?

4

1 回答 1

0

试试下面的代码:

        public ListView lv;

            lv = (ListView) findViewById(R.id.ListView01);
            lv.setAdapter(adapter);
    lv.setTextFilterEnabled(true);
    lv.setBackgroundResource(R.drawable.background);
    lv.setCacheColorHint(00000000);
    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {


        }
    });


         class MySimpleArrayAdapter extends ArrayAdapter<String> {
    private Context context;

    public MySimpleArrayAdapter(Context context) {
        super(context, R.layout.list);
        this.context = context;

    }

    public int getCount() {
        return names.size();
    }

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


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

        View rowView = convertView;

        if (rowView == null) {

            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            rowView = vi.inflate(R.layout.list, null);
        }
        TextView name = (TextView) rowView.findViewById(R.id.Name);
        TextView number = (TextView) rowView.findViewById(R.id.no);


        return rowView;
    }
}
于 2012-10-03T17:35:03.490 回答