活动中textview中的字体更改

时间:2012-11-30 05:44:52

标签: android

在我的应用程序中,我在一个活动中显示一些数据。如果用户点击1个图像,数据的字体大小应该改变。但在我的情况下没有发生任何事情。我已经使用AdpaterClass设置了该页面的数据。 / p>

我的活动代码:

public class NewsDescription extends Activity
{

     public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);  
            setContentView(R.layout.newsdescriptionrow);      

            Gallery gl=(Gallery)findViewById(R.id.GalleryNewsDesc);
            NewsDescriptionAdapter adapter =new NewsDescriptionAdapter(this);
            gl.setAdapter(adapter);   

            ImageView img=(ImageView)findViewById(R.id.fontimage);

            TextView prevnews=(TextView)findViewById(R.id.prevnews);

            prevnews.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    System.out.println("subbu"); 

                }
            });

            img.setOnClickListener(new View.OnClickListener()     ---------->this is the clicking part of the image.
            {               
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    System.out.println("Inside click");

                }
            });            


        }


}

我的adpater课程:

public class NewsDescriptionAdapter extends  BaseAdapter
{
    private static Context contxt;

    String[] body= {};//new String[30];
    String[] heading= {};//new String[30];
    private Integer mImageIds = R.drawable.font;
    int font = 10;
//  
    NewsDescriptionAdapter(Context conxt)
    {
//      System.out.println("inside cons");
        this.contxt=conxt;
        getelement();
    }   
    public NewsDescriptionAdapter(OnClickListener onClickListener) {
        System.out.println("prakashhh....");
        font = 20;
        getelement();
        // TODO Auto-generated constructor stub
    }
    public void getelement()
    {
        String[] url=context.getInstance().getselectedUrl();
        int count = Integer.parseInt((String)context.getInstance().getAppVariable("count"));
         String URL = "http://m.indiatoday.in/xml/stories/"+url[count];
         TaplistingParser parser = new TaplistingParser();

            URL=URL.replace(" ","");
//          System.out.println("url="+url);
            String xml= parser.getXmlFromUrl(URL);
            Document doc=parser.getDomElement(xml);                 
            NodeList n1 = doc.getElementsByTagName("item");
            body = new String[n1.getLength()];
            heading = new String[n1.getLength()];
            for( int i = 0 ; i < n1.getLength(); i++ )
            {
//              HashMap<String, String> map = new HashMap<String, String>();
                Element e = (Element) n1.item(i);
                body[i]=parser.getValue(e, "body");
                heading[i]=parser.getValue(e, "headline");
//              map.put("Body", parser.getValue(e,"body"));             
//              menuItems.add(map);
            }
    }
//  }
    @Override
    public int getCount() 
    {
        // TODO Auto-generated method stub
        return body.length;
    }

    @Override
    public Object getItem(int position) 
    {
        // TODO Auto-generated method stub
        return body[position];
    }

    @Override
    public long getItemId(int position) 
    {
        // TODO Auto-generated method stub
        return position;
    }

     View rowView ;
     int Position=0;
    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {
        this.Position=position;
        // TODO Auto-generated method stub

        rowView = LayoutInflater
                 .from(parent.getContext())
                 .inflate(R.layout.newsdescriptionrow, null);      -------> This is the layout where that imageview is present.

          TextView prevnews=(TextView)rowView.findViewById(R.id.prevnews);
          TextView nextnews=(TextView)rowView.findViewById(R.id.nextnews);

          ImageView img=(ImageView)rowView.findViewById(R.id.fontimage);
          img.setImageResource(mImageIds);

          prevnews.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                System.out.println("inside prev");

            }
        });

          nextnews.setOnClickListener(new View.OnClickListener() 
          {
            @Override

            public void onClick(View arg0) {
                System.out.println("inside next");
                int count = Integer.parseInt((String)context.getInstance().getAppVariable("count"));
                count ++;
                context.getInstance().setAppVariable("count",Integer.toString(count));


                // TODO Auto-generated method stub

            }
        });



         TextView textViewhead = (TextView) rowView
                    .findViewById(R.id.name_DescHeading);
         textViewhead.setText(heading[position]);

             TextView textView = (TextView) rowView
                    .findViewById(R.id.name_Desclabel);
            textView.setText(body[position]);
            System.out.println("font="+font);
//          textView.setTextSize(font);

            textViewhead.setTextSize(Integer.parseInt((String)context.getInstance().getAppVariable("nd_heading_size")));
            textViewhead.setTextColor(Integer.parseInt((String)context.getInstance().getAppVariable("nd_heading_color")));
//            textViewhead.setTypeface(((String)context.getInstance().getAppVariable("nd_heading_size")));

            textView.setTextSize(Integer.parseInt((String)context.getInstance().getAppVariable("nd_content_size")));
            textView.setTextColor(Integer.parseInt((String)context.getInstance().getAppVariable("nd_content_color")));
//            textView.setTypeface(tf);





        return rowView;
    }
}

0 个答案:

没有答案