listView = new ListView(this);
1.在不涉及xml布局的情况下,怎么设置字体大小呀?
2.以及如果一行中有两条数据怎么设置其中间隔?

解决方案 »

  1.   

    ListView list = (ListView) findViewById(R.id.list);
    adapter = new MyAdapter(this,R.layout.main,
        R.id.row_text,
        new String[]{"Uno", "Dos", "Tres"} );
    list.setAdapter(adapter);
    //Custom Adapter class
    private class MyAdapter extends ArrayAdapter<String>{
      String[] mStrings;
      LayoutInflater mInflater;
     
      public MyAdapter(Context context, int resource, int textViewResourceId,
        String[] strings) {
       super(context, resource, textViewResourceId, strings);
       mStrings = strings;
       mInflater = (LayoutInflater) FirstAct.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      }
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
       View view = mInflater.inflate(R.layout.main,null, false);
       TextView text = (TextView) view.findViewById(R.id.row_text);
       text.setText(mStrings[position]);
       Spannable str = (Spannable) text.getText();
       str.setSpan(new StyleSpan(Typeface.BOLD), 0, str.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
      
       return view;
      }
     }