0
的列表中選擇我做了顏色的名單,我想改變ID爲「用戶名」的TextView
文本的顏色改變機器人的TextView的文本顏色只要有人點擊列表。我的項目的一個嘗試下面的代碼,但它不工作。我中號無法弄清楚什麼是錯在下面的代碼:如何根據所選擇的顏色,從色彩
public class UserInformation extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_information);
Bundle app = getIntent().getExtras();
if (app == null) {
return;
}
final TextView Name = (TextView) findViewById(R.id.NameOfUser);//refernce to textview
Name.setText(app.getString("user_information"));
String[] color = {"Blue", "Red", "Green"};
ListAdapter mylist = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, color);
ListView renuList = (ListView) findViewById(R.id.Mylist);
renuList.setAdapter(mylist);
renuList.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
String item = String.valueOf(adapterView.getItemIdAtPosition(i));
if (item == "Green") {
Name.setTextColor(Color.GREEN);// suppose I want to set the color to green if green is selected
}
}
}
);
}
你知道這樣的Java的基礎知識,如何在Java中比較字符串? – Selvin
使用ContextCompat.getColor(context,R.color.XXX)獲取顏色! – XxGoliathusxX