2013-10-23 3 views
0

위치가있는 목록 뷰가 있습니다. 위치를 클릭하면이 위치 내에서 수행 할 작업이 표시됩니다. 모든 작업이 완료되면 이제 확인 버튼을 클릭하십시오. 목록보기 배경색의 선택된 위치 행을 변경하고 싶습니다. I 버튼이 전체 목록보기 녹색을 변경하는 순간선택한 목록보기 행의 배경 설정

mOkBtn.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      View listView = getActivity().findViewById(R.id.area_list); 
      listView.setBackgroundColor(Color.GREEN); 
      mArea.checkResult = CheckResult.OK; 
      mArea.checkTimeStamp = System.currentTimeMillis()/1000L; 
      showResults(); 
     } 
    }); 

에 대해 지금까지 가지고 있지만, 그것은 단지 선택된 행을 변경하는 방법을하지 않도록 메신저 무엇. 다음과 같이

들으

+0

당신이 선택한 항목의 색상을 유지 하시겠습니까? –

답변

0

당신은 당신이 목록보기 다음

android:cacheColorHint="#00000000" 
android:scrollbarFadeDuration="0" 
으로 XML의 일부 코드를 추가 스크롤 할 때

ListView listview=new ListView(this); 
listview.setBackgroundColor(Color.WHITE); 

이 목록보기 블랙 표시되면, 목록보기의 배경 색상을 설정할 수 있습니다

여러분에게 도움이 될 것이라고 생각합니다.

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@drawable/plainbg"> 


<ListView 
android:id="@+id/foodlistview" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:cacheColorHint="#00000000" 
android:scrollbarFadeDuration="0" 
android:divider="@android:color/white" 
android:dividerHeight="2px" 
></ListView></RelativeLayout> 
0

색상을 설정하려면 셀렉터가 필요합니다. 당신은 안드로이드를 사용하여 목록에서이 작업을 설정할 수 있습니다 listSelector 속성으로 :

<ListView 
android:id="@+id/foodlistview" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:cacheColorHint="#00000000" 
android:scrollbarFadeDuration="0" 
android:divider="@android:color/white" 
android:dividerHeight="2px" 
android:listSelector="list_selector" 
></ListView> 

그리고 list_selector.xml :

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_enabled="false" android:state_focused="true" 
     android:drawable="@drawable/item_disabled" /> 
    <item android:state_pressed="true" 
     android:drawable="@drawable/item_pressed" /> 
    <item android:state_focused="true" 
     android:drawable="@drawable/item_focused" /> 
</selector> 
관련 문제