나는 다음과 같이 RecyclerView
을 동적으로 생성했습니다. 클릭 한 항목을 클릭하면서 강조하고 싶습니다. 클릭 후 다음 Activity
으로 이동합니다. 아래 배경 XML을 받았습니다 :RecyclerView 클릭시 강조 표시
hRecyclerView.setBackgroundResource(R.drawable.mylistview_background);
설정 방법이 아닌가요? 내가 여기서 뭘해야하지? 어떤 도움이 많이 감사합니다
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<gradient android:endColor="#22000000" android:startColor="#a7a2288f" android:angle="270" />
</shape>
</item>
<item android:state_focused="true">
<shape>
<gradient android:endColor="#2200ff00" android:startColor="#a2008f00" android:angle="270" />
</shape>
</item>
</selector>
hRecyclerView = (RecyclerView) findViewById(R.id.my_history_view);
// use a linear layout manager
hLayoutManager = new LinearLayoutManager(this);
hRecyclerView.setLayoutManager(hLayoutManager);
hRecyclerView.setVerticalScrollBarEnabled(false);
hRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST));
hRecyclerView.setBackgroundResource(R.drawable.mylistview_background);
hAdapter = new HistoryAdapter(history, this);
hRecyclerView.setAdapter(hAdapter);
hRecyclerView.addOnItemTouchListener(
new RecyclerItemClickListener(context, new RecyclerItemClickListener.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
// do whatever
if(position>0) {
History his = history.get(position - 1);
Intent intent = new Intent(getApplicationContext(), TrackActivity.class);
intent.putExtra("from", his.src_station);
intent.putExtra("to", his.dest_station);
intent.putExtra("train_no", his.train_no);
intent.putExtra("train_name", his.train_name);
startActivity(intent);
overridePendingTransition(R.anim.right_in, R.anim.left_out);
}
}
})
);
hRecyclerView.setItemAnimator(new DefaultItemAnimator());
mylistview_background.xml!
당신이 클릭 이벤트를 처리하기 위해 ViewHolder 클래스에 onClickListenner를 사용하지 않는 이유가 있습니까 ? 어제 많은 시간을 들여 이러한 경우에 가장 적합한 솔루션을 제시했으며 나에게도 그렇게 쉬운 방법이었습니다. 내가 모르는 뭔가가 있으면 알려주세요. – Ced