Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 活动中文本视图中的字体更改_Android - Fatal编程技术网

Android 活动中文本视图中的字体更改

Android 活动中文本视图中的字体更改,android,Android,在我的应用程序中,我在一个活动中显示一些数据。如果用户单击一个图像,数据的字体大小应该会改变。但在我的情况下,什么都没有发生。我已经使用AdpaterClass设置了此页面的数据 我的活动代码: public class NewsDescription extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanc

在我的应用程序中,我在一个活动中显示一些数据。如果用户单击一个图像,数据的字体大小应该会改变。但在我的情况下,什么都没有发生。我已经使用AdpaterClass设置了此页面的数据

我的活动代码:

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;
    }
}
公共类NewsDescriptionAdapter扩展了BaseAdapter
{
私有静态上下文;
String[]body={};//新字符串[30];
String[]heading={};//新字符串[30];
私有整数mImageIds=R.drawable.font;
int font=10;
//  
NewsDescriptionAdapter(上下文上下文上下文)
{
//系统输出打印项次(“内部cons”);
this.contxt=conxt;
getelement();
}   
公共新闻描述适配器(OnClickListener OnClickListener){
System.out.println(“Prakashh…”);
font=20;
getelement();
//TODO自动生成的构造函数存根
}
public void getelement()
{
字符串[]url=context.getInstance().getselectedUrl();
int count=Integer.parseInt((字符串)context.getInstance().getAppVariable(“count”));
字符串URL=”http://m.indiatoday.in/xml/stories/“+url[计数];
TaplistingParser=新的TaplistingParser();
URL=URL.replace(“,”);
//System.out.println(“url=“+url”);
字符串xml=parser.getXmlFromUrl(URL);
Document doc=parser.getdoElement(xml);
NodeList n1=doc.getElementsByTagName(“项目”);
body=新字符串[n1.getLength()];
heading=新字符串[n1.getLength()];
对于(int i=0;i这是显示该imageview的布局。
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(mimageId);
prevnews.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图arg0){
//TODO自动生成的方法存根
System.out.println(“内部版本”);
}
});
nextnews.setOnClickListener(新视图.OnClickListener()
{
@凌驾
公共void onClick(视图arg0){
System.out.println(“内部下一步”);
int count=Integer.parseInt((字符串)context.getInstance().getAppVariable(“count”));
计数++;
context.getInstance().setAppVariable(“count”,Integer.toString(count));
//TODO自动生成的方法存根
}
});
TextView textViewhead=(TextView)行视图
.findViewById(R.id.name_DescHeading);
textViewhead.setText(标题[位置]);
TextView TextView=(TextView)行视图
.findViewById(R.id.name\u描述标签);
textView.setText(主体[位置]);
System.out.println(“font=“+font”);
//textView.setTextSize(字体);
textViewhead.setTextSize(Integer.parseInt((字符串)context.getInstance().getAppVariable(“nd_heading_size”));
textViewhead.setTextColor(Integer.parseInt((字符串)context.getInstance().getAppVariable(“nd_heading_color”));
//textViewhead.setTypeface(((字符串)context.getInstance().getAppVariable(“nd_heading_size”));
textView.setTextSize(Integer.parseInt((String)context.getInstance().getAppVariable(“nd_content_size”));
textView.setTextColor(Integer.parseInt((字符串)context.getInstance().getAppVariable(“nd_content_color”));
//textView.setTypeface(tf);
返回行视图;
}
}

如果您的listview中有这些元素,那么这将不起作用。在适配器的getView方法中添加一个侦听器(这可能是一种丑陋的方式)。感谢Andro Selva…我认为我正在以某种丑陋的方式做,因为我是新手。无论如何,建议一些方法来实现这一点…我指出我的建议是丑陋的方法。在适配器的getview方法中添加图像的单击侦听器。Andro selva..我这样做了..现在的问题是..如果我为st timr单击图像,意味着字体正在设置…如果我再次单击该图像,意味着它应该保留原始字体(这不会发生)。。