In OnItemClick() method I load new Activity. My ListView item blinks on OnItemClick() (I mean, changes brightness a little or something - don't know how to say it correctly), but blinks just for a moment and then returns to its previous appearance before new Activity is loaded. I want that ListView item stayed blinked all the time before new Activity is loaded, not for just a little moment. How to do it?
-
I understand that you are trying to blink item on list when they are clicked and will blink until Activity is started. Right? – mubeen Jul 25 '15 at 20:07
-
Maybe not "will blink", but stay blinked. I mean it needs some time to start new activity (or for any action I put into onItemClick()) and I want it to change brightness (or what's changed when we usually click on items) and stay something like tapped until actions in onItemClick() are done – Justin McGuire Jul 25 '15 at 20:31
-
I do not get any idea. May be you share your code, So other can help you – mubeen Jul 25 '15 at 21:09
-
@mubeen the idea is quite simple (maybe, I'm not explaining in clearly but I'll try again in other words). When you tap on an item in ListView it usually changes the way it looks like. Then something happens. In my case, it changes just for a moment, then returns to the normal state and then something happens. I need it to remain the second "tapped" way until that "something" happens. E.g., if an item is blue and when it's clicked it becomes red, I need that it stay red all the time until everything in OnItemClick() happens, without returning it back to blue in several milliseconds – Justin McGuire Jul 25 '15 at 22:17
3 Answers
You can use View.setOnClickListener for this..
when you are passing the intent to next page change the background color of listview item
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
arg0.setBackgroundColor(Color.RED);
Intent intent = new Intent(MainActivity.this, CheckinoutPage.class);
startActivity(intent);
}
});

- 128
- 9
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);
}
}
Class ListView Adapter as
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;
}
}

- 128
- 9
The blink you are talking about is probably the items selector. For you what you want your best bet is probably to disable the default selector and implement it manually yourself.
So in the getView of your adapter I'd set an onClickListener to your convertView and when triggered, set the backgroundColour of it to blue or whatever colour and then perform the action. This way it will stay that colour until the next Activity is loaded. Thats the gist of the solution, if you need more help, let me know and I'll edit this answer.
Edit: In response to your 2nd comment below, try keeping track of the clicked list item using a public int in your adapter and reset it to something like -1 in the Activity/Fragments onResume. Then in the getView of your adapter check if this list item is the selected one, set the background colour, otherwise return it to white or whatever your default colour is.

- 8,222
- 2
- 15
- 19
-
Yes, it's a good solution, but in my case I'm not changing color. I told about color above that it be easier to understand. I need it to change the way it usually changes when onItemClick() (it looks almost the same but like behind a so much transparent black curtain... E.g., white becomes a little grayer (don't remember about other colors). I don't know how to explain that effect but it almost always looks like this when onClick() in lots of apps. I could've attached the example picture but there's no such functionality :( – Justin McGuire Jul 26 '15 at 16:37
-
Just tried to do it your way, but I don't know how to return its previous color when back to that activity (both with backbutton and navigationbutton on actionbar) – Justin McGuire Jul 26 '15 at 17:21
-
In response to your 2nd comment, try keeping track of the clicked list item using a public int in your adapter and reset it to something like -1 in the Activity/Fragments onResume. Then in the getView of your adapter check if this list item is the selected one, set the background colour, otherwise return it to white or whatever your default colour is. – Dom Jul 27 '15 at 08:33