I am creating some views in my xml file, xml file contaings list-view.
In that list-view I have list selector attribute and i defined drawable
image for selector.
My xml file follows like this:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="@+id/frameLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<com.naaima.vovinet.activity.VideoNativePlayer
android:layout_marginLeft="50dip"
android:layout_width="800dip"
android:layout_marginRight="30dip"
android:id="@+id/video_view"
android:layout_height="600dip"
android:layout_marginTop="50dip">
</com.naaima.vovinet.activity.VideoNativePlayer>
<ImageView android:src="@drawable/icon"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/imageView1"/>
<ImageView android:src="@drawable/icon"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:id="@+id/imageView2"/>
<LinearLayout android:id="@+id/linearlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/textView_channelno"
android:layout_width="130dip"
android:hint="_ _ _"
android:layout_marginLeft="1050dip"
android:layout_marginTop="20dip"
android:background="@drawable/sample"
android:gravity="center"
android:textSize="25dip"
android:visibility="gone"
android:layout_height="80dip"/>
</LinearLayout>
<FrameLayout android:id="@+id/frameLayout2"
android:layout_width="1100dip"
android:layout_height="wrap_content"
android:background="@drawable/bg1"
android:layout_gravity="bottom"
android:layout_marginLeft="100dip"
android:layout_marginBottom="15dip">
<RelativeLayout android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ProgressBar style="?android:attr/progressBarStyleHorizontal"
android:layout_width="730dip"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:layout_marginTop="30dip"
android:background="@drawable/progress_bar_bg"
android:layout_marginLeft="180dip"/>
<TextView android:id="@+id/textView_date"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="@+id/progressBar"
android:layout_marginTop="30dip"
android:layout_marginLeft="50dip"/>
<TextView android:id="@+id/textView_time"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="@+id/textView_date"
android:layout_marginTop="3dip"
android:layout_toRightOf="@+id/list"
android:layout_marginLeft="57dip"
/>
<TextView
android:id="@+id/textView_location"
android:text="Hyderabad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView_time"
android:layout_marginTop="10dip"
android:layout_marginRight="10dip"
android:layout_toRightOf="@+id/imageView_temp"
/>
<TextView
android:id="@+id/textView_temp"
android:text="35 Degrees"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView_location"
android:layout_marginRight="10dip"
android:layout_marginTop="5dip"
android:layout_toRightOf="@+id/imageView_temp"
/>
<ImageView android:id="@+id/imageView_temp"
android:src="@drawable/temp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView_time"
android:layout_toRightOf="@+id/list"
android:layout_marginLeft="20dip"/>
<ImageView android:id="@+id/imageView_logo"
android:src="@drawable/zee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dip"
android:layout_marginLeft="50dip"/>
<ImageView android:id="@+id/imageView_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/arrow_left_gray"
android:layout_marginTop="110dip"
android:layout_marginLeft="23dip"/>
<TextView android:id="@+id/txt_channelName"
android:text="M-Tunes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="110dip"
android:layout_marginLeft="50dip"/>
<ImageView android:id="@+id/imageView_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/arrow_right_gray"
android:layout_marginTop="110dip"
android:layout_marginLeft="150dip"/>
<ListView android:id="@+id/list"
android:layout_width="690dip"
android:layout_height="125dip"
android:layout_below="@+id/progressBar"
android:layout_marginLeft="220dip"
android:listSelector="@drawable/highlight_bar"/>
<ImageView android:id="@+id/imageView_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/arrow_up_gray"
android:layout_below="@+id/progressBar"
android:layout_marginTop="5dip"
android:layout_marginLeft="180dip"/>
</RelativeLayout>
</FrameLayout>
</FrameLayout>`
Row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView android:text="TextView"
android:id="@+id/textView_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
And java code is like following
ListView lv = (ListView) findViewById(R.id.list);
String[] values = new String[] { "Now:Harry Potter and Deathly Hellows", "Lord of the Rings:Two Towers", "Lord of the Rings:Return of King",
"rd of the Rings:Honneypot solo Dance"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.row,R.id.textView_list, values);
lv.setAdapter(adapter);
lv.setSelector(R.drawable.highlight_bar);
lv.setDivider(null);
If I am executing only listview with row xml code list selector working fine.
If I am pressing up and down arrows it’s working fine. But I am integrating
listview with above code it’s not working and if I am pressing up and arrows
in keyboard no use (focusing not going to listview side).
Have you tried calling “requestFocus()” on the listView in your code after setting android:focusable=”true” in the xml? From the View docs:
“Call this to try to give focus to a specific view or to one of its descendants. A view will not actually take focus if it is not focusable (isFocusable() returns false), or if it is focusable and it is not focusable in touch mode (isFocusableInTouchMode()) while the device is in touch mode. See also focusSearch(int), which is what you call to say that you have focus, and you want your parent to look for the next one. This is equivalent to calling requestFocus(int, Rect) with arguments FOCUS_DOWN and null.”