如何为任何特定行着色?
我曾尝试使用该getView
方法,但没有成功。我不想根据条件为任何行着色,我只想用特定颜色对行进行硬编码。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv=(TextView) findViewById(R.id.tv1);
listview= (ListView) findViewById(R.id.listview1);
mylist.add("random1");
mylist.add("random2");
mylist.add("random3");
mylist.add("random4");
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, mylist);
listview.setBackgroundColor(Color.CYAN);
listview.setAdapter(adapter);
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, final View view,
int position, long id) {
String position2 =String.valueOf(position);
Intent i = new Intent(MainActivity.this,minutes.class);
i.putExtra("position",position2 );
startActivity(i);
}
});
}
我的 XML 看起来像:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<ListView
android:id="@+id/listview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false">
</ListView>