Skip to content Skip to sidebar Skip to footer

Using Setselected On A Textview Inside A Listitem Inside A Listview

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. Because the textview i

Solution 1:

I also had a similar need and came up with the following approach. I implemented SimpleCursorAdapter.ViewBinder in my activity. It is a single method that looks like this public boolean setViewValue(View view, Cursor cursor, int columnIndex). Inside I get the id from the View. If it is the correct one, I cast it to a TextView and setText(); on it followed by setSelected(true) and return true. On views I'm not interested in, I return false and let TextView handle it. No need to create a custom TextView.

Solution 2:

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 stubsetSelected(true);
  }

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

    }
  }


 }

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>

Solution 3:

You can get each view record in your list, using getChildCount() and getChildAt(i) Here are my example

View getViewPattern;
    TextView getTextByPattern;
    String contentAnswerInPattern;
    for (int i = 0; i < listView.getChildCount(); i++) {
        getViewPattern = listView.getChildAt(i);
        getTextByPattern = (TextView) getViewPattern.findViewById(R.id.value_a);
        contentAnswerInPattern = getTextByPattern.getText().toString().trim();
    }

Post a Comment for "Using Setselected On A Textview Inside A Listitem Inside A Listview"