ちょっと、私はリストビュー内の特定の位置の色を変更しようとしています。私がしたいポジションの色を変えることができますが、ハイライトしたいアイテムのリストから10のポジションが強調表示されているパターンがあるように見えます。特定のリストビューの色を変更する問題
私のカスタムadapter.javaが色の変更コードでどのように設定されているかを確認します。
package com.example.zach.listview;
import android.content.Context;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
class CustomAdapter extends ArrayAdapter<String>{
public CustomAdapter(Context context, String[] routes) {
super(context, R.layout.custom_row ,routes);
}
@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater routeInflater = LayoutInflater.from(getContext());
View customView = convertView;
if(customView == null){customView = routeInflater.inflate(R.layout.custom_row, parent, false);}
String singleRoute = getItem(position);
TextView routeText = (TextView) customView.findViewById(R.id.routeText);
routeText.setText(singleRoute);
//if (getItem(position).equals("Information")){
// routeText.setBackgroundColor(Color.GRAY);
//}
if(position == 0)
{
routeText.setBackgroundColor(Color.GRAY);
}
return customView;
}
}
[Androidの代替行の色をリストビューで表示](http://stackoverflow.com/questions/13109840/android-alternate-row-colors-in-listview) –
代わりにrecyclerviewを試してください –