einstellen Ich habe eine benutzerdefinierte Listview mit drei TextView. Jede Reihe zeigt Personenname, E-Mail und Tag.Jetzt möchte ich eine rote Farbe für welche Person Tage sind weniger als 120 und ich möchte auch eine grüne Farbe für welche Person Tage sind größer als 120.Wie ich mein Problem zu lösen ?? Jede Hilfe wird geschätzt.wie man ListView Hintergrund Elementfarbe in Android
person_show
public class person_show extends Activity
{
static int total_day;
List<personInfo>PersonInfo;
public MyAdapter adapter;
static Vector<String>email = new Vector<>();
static Vector<String>name = new Vector<>();
static Vector<String>city = new Vector<>();
static String[] Name,Email,City;
ListView list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.personlistview);
Firebase.setAndroidContext(this);
//show_person();
Person_Show();
}
private void Person_Show()
{
PersonInfo = new ArrayList<>();
list = (ListView)findViewById(R.id.list);
String[] value = new String[]{" No Data Found"};
ArrayAdapter<String> Adapter = new ArrayAdapter<String>(this,R.layout.persontextview,value);
list.setAdapter(Adapter);
PersonInfo.add(new personInfo("abc","[email protected]","65 days"));
PersonInfo.add(new personInfo("xyz","[email protected]","130 days"));
PersonInfo.add(new personInfo("pqr","[email protected]","70 days"));
PersonInfo.add(new personInfo("ABC","[email protected]","140 days"));
for(int i = 0;i<email.size();i++)
PersonInfo.add(new personInfo(name.get(i),email.get(i),"150 days"));
adapter = new MyAdapter(this,PersonInfo);
list.setAdapter(adapter);
}
MyAdapter
public class MyAdapter extends BaseAdapter
{
List<personInfo>PersonInfo;
Context context;
public MyAdapter(Context context,List<personInfo>personInfo)
{
this.context = context;
this.PersonInfo = personInfo;
}
@Override
public int getCount() {
return PersonInfo.size();
}
@Override
public Object getItem(int position) {
return PersonInfo.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.person_layout,parent,false);
TextView txt_name,txt_email,txt_phone;
txt_name = (TextView)view.findViewById(R.id.t_name);
txt_email = (TextView)view.findViewById(R.id.t_email);
txt_phone = (TextView)view.findViewById(R.id.t_phone);
txt_name.setText(PersonInfo.get(position).getName());
txt_email.setText(PersonInfo.get(position).getEmail());
txt_phone.setText(PersonInfo.get(position).getPhone());
return view;
}
}
person
public class personInfo
{
String name,phone,email;
public personInfo(String name,String email,String phone)
{
this.name = name ;
this.email = email;
this.phone = phone;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
post Ihren Adapter Code – Rajasekhar
Also was hast du probiert? Welches Problem haben Sie? – Piyush
plesae fügen Sie einige Adapter-Code. –