mydb = new Databaseop(Main15Activity.this);
Intent i = getIntent();
final String rname = i.getStringExtra("rname");
t1.setText(rname);
Databaseop dp = new Databaseop(ctx);
mydb = new Databaseop(Main15Activity.this);
Cursor data = mydb.getListContents(dp, rname);
if (data.getCount() == 0) {
Toast.makeText(Main15Activity.this, "There are no contents in this list!", Toast.LENGTH_LONG).show();
} else {
while (data.moveToNext()) {
String theListcon = data.getString(0);
final String[] contents = convertStringToArray(theListcon);
listAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,contents){@Override
public View getView(int position , View convertView, ViewGroup parent){
View view=super.getView(position, convertView, parent);
TextView textView=(TextView)view.findViewById(android.R.id.text1);
textView.setTextColor(Color.WHITE);
String content=getItem(position);
if(content.equals(tagcontent))
{
textView.setBackgroundColor(Color.GREEN);
Intent intent=getIntent();
String user=intent.getStringExtra("name");
String rank=intent.getStringExtra("rank");
Databaseop dp = new Databaseop(ctx);
dp.reports(dp, user, rank, tagcontent);
Toast.makeText(Main15Activity.this, "one room visited", Toast.LENGTH_SHORT).show();
}
return view;
}
};
l1.setAdapter(listAdapter);
我希望将字符串与列表视图项匹配,如果项与字符串匹配,则项的背景必须变为绿色,列表视图中的项目来自数据库。
答案 0 :(得分:0)
在将背景设置为项目列表时,您必须设置1
条件。
如下所示。
else
答案 1 :(得分:0)
您可以在适配器中执行此操作。当单元格膨胀时,检查字符串是否匹配。如果是,请获取所需的视图,并相应地更改其背景。