简体   繁体   中英

How to change font and size in listview

I must get the items from a listview that already exists and is invisible and I must put the items in another empty listview that is visible. I know there are lots of questions about this, but mine is different. Because I must use it with a RSSReader it is even harder, because I tried to adapt the code but.... How do I transfer the items from the invisible listview, to the visible one and also change the font and the size of the font?

TextView feedtitle = (TextView) findViewById(R.id.feedtitle);
        TextView feedpubdate = (TextView) findViewById(R.id.feedpubdate);
        ListView itemlist = (ListView) findViewById(R.id.itemlist);

        if (feed == null)
        {
            feedtitle.setText("No RSS Feed Available");
        return;
        }

        feedtitle.setText(feed.getTitle());
        feedpubdate.setText(feed.getPubDate());

        ArrayAdapter<RSSItem> adapter = new ArrayAdapter<RSSItem>(this,android.R.layout.simple_list_item_1,feed.getAllItems());

        itemlist.setAdapter(adapter);
        itemlist.setOnItemClickListener(this);
        itemlist.setSelection(0);

You are correct on the textsize, ish.

Please follow this sample. (Note: I am assuming a great deal, such as replace RSSItem with a desired string.)

public void MyAdapter extends BaseAdapter {
    List<String> mVisibleData = new ArrayList<String>();
    Queue<String> mInvisibleData = new LinkedList<String>();

    public void addDataToInvisible(String string) {
            mInvisibleData.add(string);
    }

    public void moveInvisibleToVisible() {
        mVisibleData.add(mInvisibleData.poll());
        notifyDataSetChanged();
    }

    @Override public int getCount() {
            return mVisibleData.size();
    }

    @Override public String getItem(int position) {
        return mVisibleData.get(position);
    }

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

    @Override public View getView(int position, View convertView, ViewGroup parent) {
        TextView ret = new TextView(getContext());
        Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "mtfont.ttf");
        ret.setTypeFace(tf);
        ret.setTextSize(18.0f);
            ret.setText(mVisibleData.get(position);
        return ret;
    }
}

Now, you will have to work the finer details, but I am sure this will be close to your needs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM