【问题标题】:How to set font size when class extends from Activity not BaseAdapater当类从 Activity 扩展而不是 BaseAdapter 时如何设置字体大小
【发布时间】:2017-06-12 11:21:43
【问题描述】:

您好,我的 android 活动有一个列表视图,我需要增加/放大其字体大小。我已经阅读了解决方案,您为此覆盖了 baseadapter 的 getview。但是我的课程扩展了 Activity 而不是 BaseAdapter。在这种情况下我该怎么办?这是我的代码

public class SaltnPepperActivity extends Activity implements android.widget.CompoundButton.OnCheckedChangeListener{

private ListView menuList;
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_saltn_pepper);

    menuList = (ListView) findViewById(R.id.list1);
    menuList.setOnItemClickListener(new AdapterView.OnItemClickListener(){

        @Override
        public void onItemClick(AdapterView<?> parent, View v, int pos, long id){
       ....
 }
    });

}

这个活动是通过主要活动的意图调用的

MainActivity

ImageButton saltnPepperButton = (ImageButton) findViewById(R.id.btnSaltnPepper);

    saltnPepperButton.setOnClickListener(new View.OnClickListener(){

        @Override
        public void onClick(View v){
            //goto new page
            Intent menuIntent = new Intent(v.getContext(), SaltnPepperActivity.class);
            Log.d("MainActivity", "Starting new Activity");
            ///startActivityForResult(menuIntent, 0);
            startActivity(menuIntent);
            Log.d("MainActivity", "Started new Activity");
        }
    });

更新 将列表绑定到数据的代码

Log.d("Menu", "Binding category to menulist");
        //load categories
        try{
            //get names from categories
            //ArrayAdapter<Category> catAdapter = new ArrayAdapter<Category>(this,  R.layout.menulist, R.id.nameText, categories);
            CategoryAdapter catAdapter = new CategoryAdapter(this, R.layout.menulist, categories);
            ListView list = (ListView)findViewById(R.id.list1);
            list.setAdapter(catAdapter);
            //SparseBooleanArray checkedItemPositions = list.getCheckedItemPositions();
        }
        catch(Exception e){
            e.printStackTrace();
        }

【问题讨论】:

  • 您的适配器设置在列表视图的什么位置?
  • @Samra 你能看到列表吗?你的 menuList.setAdapter(adapter) 方法在哪里?
  • 好的,我也将分享它..我通过解析 xml 文件与数据绑定
  • 更新中添加代码

标签: android listview textview android-adapter


【解决方案1】:

感谢 Gurvinder 和 Jaydeep。我在另一个类 CategoryAdapter 中找到了我的 setAdapter 函数,其中我定义了继承自 ArrayAdapter 的自定义适配器类。在那里设置字体大小,它的工作原理!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多