Android:清除以前的数据并在textview中显示

时间:2012-03-27 07:06:55

标签: android textview

我正在创建一个应用程序,我必须在文本视图中填充动态文本,但我的问题是在少数情况下我的数据正常,但有时在任何textview中有些数据被错过,另一次点击剩下的数据即将到来。现在我想要的是,如果数据不在文本框中,下一次文本框不应显示以前的数据。相反,应该显示新数据而不是预先数据**我正在使用** textView.setText(“”)。我的代码如下:

image1.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View view)
        {
            if (isFirstImage)
            {


                text2.setText("");

                System.out.println("text2"+text2.toString());
                applyRotation(0, -90);
                isFirstImage = !isFirstImage;
                Typeface tf2 = Typeface.createFromAsset(getAssets(), "fonts/CataneoLightbT.ttf");


                text1.setText(textHeadLine);
                text2.setText(textDesc);
                text1.setMaxLines(Integer.MAX_VALUE);
                text2.setMaxLines(Integer.MAX_VALUE);

                System.out.println("Headline::  "+textHeadLine);
                System.out.println("textDesc::  "+textDesc);
                System.out.println(GalleryNewActivity.parsedExampleImageDesc.get(GalleryNewActivity.positionDesc).toString());
                System.out.println(GalleryNewActivity.parsedExampleImageHeadLine.get(GalleryNewActivity.positionDesc).toString());
                text1.setTypeface(tf2);
                text2.setTypeface(tf2);

                text1.setMaxLines(Integer.MAX_VALUE);
                text2.setMaxLines(Integer.MAX_VALUE);

                text1.setVisibility(View.VISIBLE);
                text2.setVisibility(View.VISIBLE);






            } else
            {

                Typeface tf2 = Typeface.createFromAsset(getAssets(), "fonts/CataneoLightbT.ttf");
                text1.setText(textHeadLine);
                text2.setText(textDesc);

                text1.setTypeface(tf2);
                text2.setTypeface(tf2);

                applyRotation(0, 90);


                isFirstImage = !isFirstImage;

                //text1.setText("");

                text1.setVisibility(View.GONE);
                text2.setVisibility(View.GONE);
                text2.invalidate();
            }
        }
    });

}

1 个答案:

答案 0 :(得分:0)

试试这段代码:

image1.setOnClickListener(new View.OnClickListener()
{
    public void onClick(View view)
    {
        if (isFirstImage)
        {
            System.out.println("text2"+text2.toString());
            applyRotation(0, -90);
            isFirstImage = !isFirstImage;
            Typeface tf2 = Typeface.createFromAsset(getAssets(), "fonts/CataneoLightbT.ttf");

            text1.setVisibility(View.VISIBLE);
            text2.setVisibility(View.VISIBLE);

            text1.setMaxLines(Integer.MAX_VALUE);
            text2.setMaxLines(Integer.MAX_VALUE);
             text1.setTypeface(tf2);
            text2.setTypeface(tf2);

            text1.setText(textHeadLine);
            text2.setText(textDesc);

            System.out.println("Headline::  "+textHeadLine);
            System.out.println("textDesc::  "+textDesc);
            System.out.println(GalleryNewActivity.parsedExampleImageDesc.get(GalleryNewActivity.positionDesc).toString());
            System.out.println(GalleryNewActivity.parsedExampleImageHeadLine.get(GalleryNewActivity.positionDesc).toString());

             view.invalidate();

        } else
        {

            applyRotation(0, 90);

            isFirstImage = !isFirstImage;

            text1.setVisibility(View.GONE);
            text2.setVisibility(View.GONE);

            view.invalidate();
        }
    }
});

}