你好傢伙請幫助一個Noob這裏,剛剛開始學習Android。 基本上我有一個活動,有TextView和每個Textview我設置onfocusListener和一切工作完美。 這裏是佈局例如國家代碼英國如何ListView OnFocusChangeListener對數組列表項xml
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50.0dip"
android:background="@drawable/button5_background">
<ImageView
android:layout_width="65dp"
android:layout_height="104dp"
android:id="@+id/afrflag"
android:layout_gravity="center_vertical"
android:src="@drawable/ukflag" />
<TextView
android:background="@drawable/custom_selector"
android:id="@+id/uk"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/uk"
android:textColor="@color/white"
android:textSize="18.0sp"
android:focusable="true"
android:focusableInTouchMode="true" />
</LinearLayout>
這裏的代碼OnFocusChangeListener英國
TextView btnuk = (TextView) findViewById(R.id.uk);
btnuk.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
if (hasFocus) {
videoList.clear();
fetchVideouk();
}
}
});
,所以我決定要玩,讓arrays.xml並把所有的國家,去嘗試列表視圖而不是TextView,我不得不創建如此多的行作爲按鈕。
這裏是我的array.xml
<string-array
name="countryView">
<item>@string/uk</item>
<item>@string/frn</item>
<item>@string/ita</item>
<item>@string/ger</item>
</string-array>
</resources>
,並與上面的代碼我看到XML的列表視圖
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/custom_selector">
<ListView
android:background="@drawable/button5_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/country_names"
android:entries="@array/countryView"
/>
</LinearLayout>
國名上我的看法加載,但我不知道如何設置每個項目(國家)的焦點
ListView listView;
String[] uk;
uk = getResources().getStringArray(R.array.countryView);
listView = (ListView) findViewById(R.id.country_names);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, uk);
listView.setAdapter(adapter);
listView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
if (hasFocus) {
videoList.clear();
fetchVideosuk();
}
}
});
然後如何設置下一個項目的焦點?例如ger,Ita等我相信這是不正確的,但我不明白如何?
你可以把一些截圖定義你想要達到什麼? – EEJ