I am (trying to do) writing a program without xml files (the android documentation says that it is possible) but I have a lot difficulties to find informations for some details.
I would like to replace the ugly orange color when an item is being touched by an neutral color. Dose somebody know how we can do it inside the program? for a ListView which has not a R.loayout representation?
Thanks in advance for answers…
some talks about this:
ColorStateList c = new ColorStateList( new int[][] { new int[] { android.R.attr.state_pressed}, new int[1] }, new int[] { Color.rgb(50, 50, 255), Color.BLACK, });
But how to set it to my list view?
the creation of the list view is the following:
private class mybaseAdapter extends BaseAdapter {
@Override
public int getCount() {
if (portList == null)
return 0;
return portList.size();
}
@Override
public Object getItem(int position) {
Log.v("getItem", portList.get(position).toString());
return portList.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Log.v("getView", portList.get(position).toString());
return portList.get(position);
}
}
ListView lv = new ListView(context);
TableRow.LayoutParams lp = new TableRow.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
lv.setAdapter(new mybaseAdapter());
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Log.v("onItemClick", "Clicked item is");
}
});
addView(lv, lp);
You can use a StateListDrawable After you’ve created it you can set it to the background of your View with
v.setBackgroundDrawable(yourStateListDrawable);