listview选中一行高亮显示

listview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View arg1, int position,
long arg3) {
// TODO Auto-generated method stub
Log.d("","setOnItemClickListener"+position);
for(int i=0;i<parent.getCount();i++){
            v=parent.getChildAt(i);
            if (position == i) {
            v.setBackgroundColor(Color.RED);
            } else {
            v.setBackgroundColor(Color.TRANSPARENT);
            }
        }

Uri uri = Uri.parse("tel:13057602765");  
Intent intent = new Intent(Intent.ACTION_DIAL, uri);  
startActivity(intent);

}
});

listview.setOnItemSelectedListener(new OnItemSelectedListener(){

@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
Log.d("","setOnItemSelectedListener"+position);
// TODO Auto-generated method stub
for(int i=0;i<parent.getCount();i++){
            v=parent.getChildAt(i);
            if (position == i) {
Log.d("","selected"+i);
            v.setBackgroundColor(Color.RED);
            } else {
            v.setBackgroundColor(Color.TRANSPARENT);
            }
        }
}

@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub

}

});

你可能感兴趣的:(ListView)