嗨,我有一個列表視圖和點擊我想顯示一個背景圖像到選定的列表項,並更改背景,如果選擇被改變。我一直在試圖實現這一點,但無法做到這一點。請幫我這一點,將不勝感激,所以如何在點擊時將背景設置爲列表視圖項並在其他點擊時動態更改
請找我使用
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
View view = convertView;
final int getstartedItemPos = position;
Resources res = getResources();
if (convertView == null) {
view = LayoutInflater.from(parent.getContext()).inflate(
R.layout.getting_starteditem, null);
}
synchronized (view) {
TextView textTopic = (TextView) view
.findViewById(R.id.indexItems);
textTopic.setText(getStartedItems[getstartedItemPos]);
textTopic.setTypeface(tf);
view.setBackgroundColor(Color.TRANSPARENT);
}
return view;
}
};
private OnItemClickListener getStartedListItem = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
// TODO Auto-generated method stub
Intent myintent = new Intent(getApplicationContext(),GetStartedWebview.class);
myintent.putExtra("SelectedItem", getStartedItems[position]);
startActivity(myintent);
}
};
感謝索倫,我這樣做,但問題是背景,如果我點擊其他項目,背景設置爲被點擊,而不是所有的項目都不會改變應該只有一個項目 – cavallo
哦!看看我的編輯,這可能會幫助 –
我做了同樣的方式,但仍然無法正常工作,背景不會改變...請幫助 – cavallo