デフォルトでは、水平リストビューで強調表示された1つのアイテムを表示する必要があり、ユーザーが水平リストビューで別のアイテムを選択したときに、そのアイテムを強調表示したい(以前のものを削除して、現在選択されているものを強調表示する)次のコード、私のアダプターで
アダプタ:-
int selectedIndex;
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
v = LayoutInflater.from(parent.getContext()).inflate(
R.layout.hlist_rowitem, null);
if (position == selectedIndex) {
v.setBackgroundColor(Color.parseColor("#abcdef"));
}
}
リストビューからアクティビティから別のアイテムを選択した後、アイテムの強調表示位置を変更するためにアクティビティで何をすべきか。
アクティビティ:-
int sIndex;
sIndex = getIntent().getIntExtra("POSITION", 0);
hlAdapter = new HSelectedAdapter(InsuranceCard.this, rowItems, sIndex);
hListView.setAdapter(hlAdapter);
hListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
//other code goes here
}
});