PDA

View Full Version : تغییر رنگ زمینه ردیف های لیست ویو



Amin-rz
یک شنبه 02 شهریور 1393, 16:38 عصر
سلام من می خوام برای زمینه هر ردیف از لیست ویو یه رنگ بذارم اما از برنامه میزنه بیرون.
از این کد استفاده می کنم تو آداپتری که ساختم:

LinearLayout ln = (LinearLayout) findViewById(R.id.linearlistlayout);
ln.setBackgroundColor(color.gold);

یه آداپتر ساختم برای هر ردیف یه عکس نمایش بده که کاملا درست عمل می کنه ولی وقتی کد بالا رو میذارم داخلش تا برای هر ردیف رنگ linear layout زمینه رو هم تغییر بده موقع اجرای برنامه میزنه بیرون.ارور میده و برنامه قطع میشه.
مشکل از چیه؟
این آداپتر:

private class AdaptereMan extends ArrayAdapter <String> {



public AdaptereMan(Context context, int resource,
int textViewResourceId, List<String> objects) {
super(context, resource, textViewResourceId, objects);
// TODO Auto-generated constructor stub
}


@Override
public View getView (int makan, View convertView, ViewGroup parent) {

LayoutInflater bazkonande = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View radif = bazkonande.inflate(R.layout.offlinerow, parent, false);
String[] radifha = string;
ImageView tasvir = (ImageView) radif.findViewById(R.id.imageView1);
TextView matn = (TextView) radif.findViewById(R.id.label);
LinearLayout ln = (LinearLayout) findViewById(R.id.linearlistlayout);
matn.setText (radifha[makan]);

if (makan == 0){
tasvir.setImageResource(R.drawable.facebook);
ln.setBackgroundColor(color.gold);
}
else if (makan == 1)
tasvir.setImageResource(R.drawable.googleplus);
else if (makan == 2)
tasvir.setImageResource(R.drawable.twitter);
else if (makan == 3)
tasvir.setImageResource(R.drawable.offlisticon);
else if (makan == 4)
tasvir.setImageResource(R.drawable.onlisticon);


return radif;
}




}


اینم xml لیست سفارشی:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="2dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="2dp" >

<LinearLayout
android:id="@+id/linearlistlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/listbg"
android:gravity="right"
android:orientation="horizontal" >

<com.example.smsbaaz.FontSalamat
android:id="@+id/label"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="15dp"
android:text="TextView"
android:textColor="#000435"
android:textSize="17sp"
android:textStyle="bold" />

<ImageView
android:id="@+id/imageView1"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginRight="10dp"
android:background="@drawable/offlisticon" />

</LinearLayout>


</LinearLayout>


در واقع میخوام برای هر ردیف رنگ اون linearlistlayout عوض بشه.

vahidhiv
یک شنبه 02 شهریور 1393, 18:14 عصر
LinearLayout ln = (LinearLayout) findViewById(R.id.linearlistlayout);
مطمئنی نباید اینطوری باشه؟


LinearLayout ln = (LinearLayout) radif.findViewById(R.id.linearlistlayout);

Amin-rz
یک شنبه 02 شهریور 1393, 22:07 عصر
ای وای :لبخند: