我有一個自定義適配器列表視圖,當我在第一個項目點擊有按鈕(「下一個)下面的列表視圖可見,第一行項目的文字顏色的變化。 上的點擊按鈕下面我想改變下一行項文本的顏色。請幫忙,謝謝。列表視圖上的按鈕進行更改項目文本顏色單擊
mainListViews.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
itemPosition =i;
String text = textView.getText().toString();
Toast.makeText(getContext(), "Selected item: " + text + " - " + i, Toast.LENGTH_SHORT).show();
song_namef.setText(text);
playSong(i);
hello.setVisibility(View.VISIBLE);
setItemNormal();
View rowView = view;
setItemSelected(rowView);
}
});
public void setItemSelected(View view){
View rowView = view;
TextView tv = (TextView)rowView.findViewById(R.id.textView);
tv.setTextColor(Color.WHITE);
}
public void setItemNormal()
{
for (int i=0; i< mainListViews.getChildCount(); i++)
{
View v = mainListViews.getChildAt(i);
TextView txtview = ((TextView)v.findViewById(R.id.textView));
txtview.setTextColor(getResources().getColor(R.color.tabsScrollColor));
}}
hello.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getContext(),"Next",Toast.LENGTH_SHORT).show();
itemPosition=itemPosition+1;
here i want to color next row of item text
}});
getView
public View getView(final int position, View convertView, ViewGroup viewGroup) {
val = position;
viewHolder = null;
if (convertView == null) {
viewHolder = new ViewHolder();
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.list_items, viewGroup, false);
// Find the child views.
viewHolder.country = (TextView) convertView.findViewById(R.id.textView);
viewHolder.cancel = (ImageView)convertView.findViewById(R.id.button);
convertView.setTag(viewHolder);
// convertView.setTag(vh);
}
else {
viewHolder = (ViewHolder) convertView.getTag();
//vh = (ViewHolder)vi.getTag();
}
String hello = countryList.get(position);
Log.d("Hello",hello);
viewHolder.country.setText(hello.substring(18));
它的列表項目視圖。我怎麼能做到按鈕按鈕點擊,因爲按鈕單擊不能調用列表視圖行! –
@SumitKumar每次點擊按鈕,都會增加列表的行索引,從而實現顏色代碼。 –
你能解釋一些代碼!請 !! –