2

我已经创建了一个 Android RSS 阅读器应用程序。我在我的 android 应用程序中有一个文本框。我正在获取 RSS 提要并将 RSS 标题存储为一个数组。我将此数组设置为标记文本。检查代码,

String MarqueeStr="";
TextView flashnews;

for (int i = 0; i < nl.getLength(); i++) {

    MarqueeStr = MarqueeStr +" | "+ Headlines.Title[i];
        }

           flashnews.setText(MarqueeStr);

现在我必须为我的选框设置一个 onclick 监听器,以便用户可以查看他们被点击的标题的详细描述。我知道如何设置它。但我的问题是,我怎样才能在用户单击选框时的选框文本?

这是我的 XML 布局,

<TextView
  android:id="@+id/flashs"
  android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:lines="1"
    android:ellipsize="marquee"
    android:layout_marginLeft="70dp"
    android:fadingEdge="horizontal"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true"
    android:singleLine="true"
    android:textColor="#e7e7e7" />

屏幕截图在这里..

在此处输入图像描述

你能看到那个“最新消息”吗?这是我的字幕文字

4

4 回答 4

1

I think that will only be possible if you will create your textviews dynamically and set id for them. like if you are having 10 news link then use 10 textviews

        TextView txt = null;
        View.OnClickListener marquee_click = new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                int selected_item = v.getTag();
                switch (selected_item) {
                case 0:

                    break;
                case 1:

                    break;
                case 2:

                    break;
                default:
                    break;
                }
            }
        };


        LinearLayout news_text_layout = new LinearLayout(getApplicationContext());
        news_text_layout.setOrientation(LinearLayout.HORIZONTAL);

        for (int i = 0; i < 10; i++) {
            txt = new TextView(getApplicationContext());
            txt.setTag(i);   // OR txt.setId(i);
            txt.setText("new " + i);
            txt.setOnClickListener(marquee_click);
            news_text_layout.addView(txt);
        }
        // ADD YOUR LINEAR LAYOUT ON WHICH YOU HAVE ADDED ALL TEXT VIEW IN YOUR LISTVIEW FOOTER.
        // NOW PERFORM SAME ANIMATION OR TRICK ON LINEAR LAYOUT WHICH YOU WERE PERFORMING ON marquee text.

Hope it can help you...

于 2012-05-08T07:29:35.097 回答
1

对于动画,看看我刚刚创建的这个。创建新项目,然后添加我提供的类和 xml 文件。

public class Test_stflowActivity extends Activity {
    LinearLayout ll = null;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        final LinearLayout ll = (LinearLayout) findViewById(R.id.linearLayout1);
        final TranslateAnimation ts = new TranslateAnimation(200, -100, 0, 0);
        ll.setAnimation(ts);
        ts.setDuration(5000);
        TextView tv = new TextView(getApplicationContext());
        tv.setText("*bharat sharma*");
        tv.setTextSize(30);
        ll.addView(tv);
        ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ll.startAnimation(ts);
            }
        });
    }
}

这是xml文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >


    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true" >

    </LinearLayout>

</RelativeLayout>

it is working for me
于 2012-05-09T09:13:11.480 回答
1

您可以将每个 FlashNews 添加为动态创建的 TextView。您可以将所有这些放在一个 Horizo​​ntalScrollView 中。并分别设置他们的听众。

对于选取框功能,您可以在代码中以编程方式滚动水平视图。

我不知道你的想法是否可以实现。(实际上可以做到,但我猜它会包含痛苦)

于 2012-05-08T06:46:58.767 回答
0

如果您将 aListView与适配器一起使用(您应该这样做),您可以使用该getItem(int position)函数来获取特定项目。

于 2012-05-08T06:32:18.483 回答