使用的setSelected上一个TextView一个的listItem内的ListView内TextView、setSelected、ListView、listItem

2023-09-04 05:15:18 作者:灵魂的所在

我试图让滚动文字(字幕)发生一个列表视图里面,但是从我的previous阅读看来我需要在我的TextView使用的setSelected(真)。

I'm trying to get scrolling text (marquee) happening inside a listview, but from my previous reading it seems I need to use setSelected(true) on my textview.

由于TextView是被里面的列表项,而不是列表视图,我似乎无法使用getView上TextView的,因此不能用的setSelected。

Because the textview is inside listitem instead of listview, I can't seem to use getView on that textView, and thus can't use setSelected.

我会试着用一些code解释:

I'll try and explain with some code:

下面是我的OnCreate:

Here is my oncreate:

setContentView(R.layout.albumsview);



    Bundle extras = getIntent().getExtras();
    String where = extras.getString("where");
    String[] whereVal = extras.getStringArray("whereVal");

    String[] columns = { BaseColumns._ID, AudioColumns.ALBUM, };

    String orderBy = BaseColumns._ID;

    albumCursor = managedQuery(
            MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, columns, where,
            whereVal, orderBy);

    ListView listView = (ListView) findViewById(R.id.listViewAlbums);
    listView.setOnItemClickListener(this);
    String[] displayFields = new String[] { AudioColumns.ALBUM };
    int[] displayViews = new int[] { R.id.albumTitle };
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
    R.layout.albumitem, albumCursor, displayFields, displayViews);
    listView.setAdapter(adapter);

在ALBUMTITLE是包含的TextView(称为字幕),我想的setSelected(真)的观点。

The "albumTitle" is the view containing the textview (called subTitle) which I want to setSelected(true).

可能有人请告诉我如何做到这一点?

Could someone please show me how to do this?

感谢您的帮助。

推荐答案

如果您使用的是简单的适配器比我只好让custome TextView的,比你的XML添加下面给出

If you are using Simple Adapter than u have to make custome TextView and than add it in your xml as given below

public class MyTextView extends TextView{

 public MyTextView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init();
    rotate();
  }

public MyTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
    rotate();
  }

public MyTextView(Context context) {
    super(context);
    init();
    rotate();
  }

private void rotate() {
    // TODO Auto-generated method stub
    setSelected(true);
  }

private void init() {
    if (!isInEditMode()) {

    }
  }


 }

和比增加custome的TextView您的 albumitem.xml ,如下图所示。

and than add custome textview in Your albumitem.xml as shown below

 <Your Package Name.MyTextView
    android:layout_marginTop="10dip" android:id="@+id/tv_parse"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:textSize="22px"
    android:textColor="#34A4c5"
    android:ellipsize="marquee"
    android:maxWidth="220dp" 
    android:fadingEdge="horizontal"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true"  
    android:singleLine="true"
    android:layout_marginLeft="10dp"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:layout_marginRight="10dp"></Your Package Name.MyTextView>