BamsBamx
BamsBamx

Reputation: 4256

How to make a list non-clickable?

i am using an AsyncTask class to search a word, so i want to appear the word "searching" in the list while proccess is executed

Okay, what I want to do is to have a non clickable list until search is completed, in order to ,if searching word is clicked nothing happens...

Which is the correct way to do this? Thanks a lot!

Upvotes: 0

Views: 185

Answers (4)

Braj
Braj

Reputation: 2160

As you are using AsyncTask, you can use a ProgressDialog with a message "searching" in onPreExecute method and dismiss it when you are done (in onPostExecute).

In this way, your ListView will also be disabled.

@Override
protected void onPreExecute() {     
    super.onPreExecute();       
    mProgressDialog = ProgressDialog.show(mContext, message, "Please wait...");
    mProgressDialog.setCancelable(false);
}

@Override
protected void onPostExecute(String result) {
    super.onPostExecute(result);
    if(mProgressDialog != null && mProgressDialog.isShowing())
        mProgressDialog.dismiss();

   // set data for listview     
}

Upvotes: 0

Wroclai
Wroclai

Reputation: 26925

While you load, search and get data you can display a header view or/and a footer view in your ListView. Simply add these views before setting the adapter. When you search for a word, call setClickable(false) on the ListView and enable your header/footer view by, for example, calling addFooterView(mFooterView) to show your message.

Notice that you have to add the views before setting the adapter.

Example:

LayoutInflater inflater = getLayoutInflater();
mFooterView = inflater.inflate(R.layout.footer, null, false);
mListView.addFooterView(mFooterView);       
mListView.setAdapter(mAdapter);

After this, feel free to call addFooterView() to show your message and call removeFooterView() to hide your message.

Upvotes: 1

waqaslam
waqaslam

Reputation: 68177

I don't know any direct solution (which there must be), but my way to do this would be:

onPreExecute:

  1. Make your ListView setEnabled(false) so that its not click-able.
  2. Set the visibility of your custom layout (containing searching message) to setVisibility(View.VISIBLE) in order to make it visible on top of your ListView. For that you need to combine your ListView and custom Layout in a FrameLayout.

onPostExecute:

  • Simply reverse the process after you have altered ListView contents

By doing this way, you can show a transparent/translucent area covering your entire ListView with a message on top or center of it.

I've used this approach in one of my project and it looks pretty much nice :)

Upvotes: 1

Jeff Bootsholz
Jeff Bootsholz

Reputation: 3068

Why not using the notification to show that the query is executing ?

Because it can ensure the searching continues even you go out to the other apps.

The question you have asked implies the user of your apps waiting a long time to search a word and do nothing else, which is undesirable for the design of Apps for humans

Upvotes: 0

Related Questions