在OnItemClick()方法中,我加载了新的Activity。我的ListView项目在OnItemClick()上闪烁(我的意思是,稍微改变亮度或某些东西 - 不知道如何正确地说出来),但只是暂时闪烁然后在加载新的Activity之前返回到它之前的外观。我希望ListView项在加载新Activity之前始终保持闪烁,而不是一会儿。怎么做?
答案 0 :(得分:1)
您可以使用View.setOnClickListener进行此操作..
当您将意图传递到下一页时,更改listview项目的背景颜色
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
arg0.setBackgroundColor(Color.RED);
Intent intent = new Intent(MainActivity.this, CheckinoutPage.class);
startActivity(intent);
}
});
答案 1 :(得分:1)
public class MainActivity extends Activity {
DataBaseAdapter dataBaseAdapter;
ListView listview;
MainListViewAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dataBaseAdapter = new DataBaseAdapter(MainActivity.this);
dataBaseAdapter.openDatabase();
listview = (ListView) findViewById(R.id.listview1);
adapter = new MainListViewAdapter(this, dataBaseAdapter.getAllMainDetails());
listview.setAdapter(adapter);
}
}
将ListView适配器作为
public class MainListViewAdapter extends BaseAdapter {
Context mContext;
LayoutInflater inflater;
private List<DetailsPOJO> details = null;
private ArrayList<DetailsPOJO> arraylist;
public MainListViewAdapter(Context context, List<DetailsPOJO> details) {
mContext = context;
this.details = details;
inflater = LayoutInflater.from(mContext);
this.arraylist = new ArrayList<DetailsPOJO>();
this.arraylist.addAll(details);
}
public class ViewHolder {
TextView checkindatetime, checkoutdatetime, latitudein, longitudein, addressin;
}
@Override
public int getCount() {
return details.size();
}
@Override
public Object getItem(int position) {
return details.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(final int position, View view, ViewGroup parent) {
final ViewHolder holder;
if (view == null) {
holder = new ViewHolder();
view = inflater.inflate(R.layout.maincustomrow, null);
// Locate the TextViews in listview_item.xml
holder.checkindatetime = (TextView) view.findViewById(R.id.checkindatetime);
holder.latitudein = (TextView) view.findViewById(R.id.latin);
holder.longitudein = (TextView) view.findViewById(R.id.longin);
holder.addressin = (TextView) view.findViewById(R.id.addin);
holder.checkoutdatetime = (TextView) view.findViewById(R.id.checkoutdatetime);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
holder.checkindatetime.setText(details.get(position).getCheckindatetime());
holder.latitudein.setText(details.get(position).getLatitudein());
holder.longitudein.setText(details.get(position).getLongitudein());
holder.addressin.setText(details.get(position).getAddressin());
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
//This part gives color on click till the next page loads
arg0.setBackgroundColor(Color.RED);
String checkindate = details.get(position).getCheckindatetime();
Intent intent = new Intent(getApplicationContext(), LatLongDeatils.class);
intent.putExtra("checkindate", checkindate);
startActivity(intent);
}
});
return view;
}
}
答案 2 :(得分:0)
你说的眨眼可能就是物品选择器。对你来说你最想要的就是禁用默认选择器并自己手动实现它。
因此,在适配器的getView中,我将onClickListener设置为convertView,并在触发时将其backgroundColour设置为蓝色或任何颜色,然后执行操作。这样它就会保持这种颜色,直到加载下一个Activity。这是解决方案的要点,如果您需要更多帮助,请告诉我,我将编辑此答案。
编辑:为了回应下面的第二条评论,请尝试使用适配器中的public int跟踪单击的列表项,并在Activity / Fragments onResume中将其重置为-1。然后在适配器的getView中检查此列表项是否为选定列表项,设置背景颜色,否则将其返回白色或默认颜色。