Asad Mehmood
Asad Mehmood

Reputation: 325

How to Enable Specific List View Item's click listener

In my Application I am Getting data from parse in which some rows Contain Description of Employees and some Not. I want to make that Happen that if description is not available on Parse of one Items then that list item can't be clicked or can perform onItemClick function.

Or Only those can be clicked those have Description which i am getting from Parse.

I really have no idea how to achieve this, is this thing can be possible in Android.

I've done all other work getting data from parse and showing in Activity but Have no Idea About it. Any Help please

my Whole Class Code is Given Below

public class FragmentActivity_DayFirst extends Fragment implements
    OnItemClickListener {
Bitmap bmp;
ListView listview;
List<ParseObject> ob;
ProgressDialog mProgressDialog;
ArrayAdapter<String> adapter;
AgendaListAdapter adapter2;
Fragment fr;
FragmentManager fm;
FragmentTransaction fragmentTransaction;
private List<GetSet> agendaList = new ArrayList<GetSet>();
List<HashMap<String, String>> aList = new ArrayList<HashMap<String, String>>();

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.activity_fragment__dayfirst,
            container, false);
    new RemoteDataTask().execute();

    return view;
}

// RemoteDataTask AsyncTask
private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        // Create a progressdialog
        mProgressDialog = new ProgressDialog(getActivity());
        // Set progressdialog title
        mProgressDialog.setTitle("Loading Details of 1st Day");
        // Set progressdialog message
        mProgressDialog
                .setMessage("Wait.. It May Take a while depending on your Bandwidth");
        mProgressDialog.setIndeterminate(false);
        // Show progressdialog
        mProgressDialog.show();
    }

    @Override
    protected Void doInBackground(Void... params) {
        ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
                "Agendas");
        query.whereEqualTo("day", "August 7th, 2015");
        query.orderByAscending("createdAt");
        try {
            ob = query.find();
            if (ob != null) {
                for (ParseObject agendas : ob) {

                    // ParseFile image = (ParseFile)
                    // complain.get("imageURL");
                    GetSet agendaGetSet = new GetSet();
                    agendaGetSet.setStartTime((String) agendas
                            .get("startTime"));
                    Log.v("post", (String) agendas.get("startTime"));
                    agendaGetSet
                            .setEndTime((String) agendas.get("endTime"));
                    Log.v("category", (String) agendas.get("endTime"));
                    agendaGetSet.setEventTitle((String) agendas
                            .get("description"));
                    Log.v("post", (String) agendas.get("description"));

                    agendaList.add(agendaGetSet);
                }
            } else {
                Log.v("post", "No Results");
            }

        } catch (ParseException e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        Log.v("post", "After query post");
        listview = (ListView) getView().findViewById(R.id.firstlistview);
        // Pass the results into ListViewAdapter.java
        adapter2 = new AgendaListAdapter(getActivity(), agendaList);
        // Binds the Adapter to the ListView
        listview.setAdapter(adapter2);
        // Close the progressdialog
        mProgressDialog.dismiss();
        // Item Click Listener for the listview
        OnItemClickListener itemClickListener = new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View container,
                    int position, long id) {
                // Getting the Container Layout of the ListView
                LinearLayout linearLayoutParent = (LinearLayout) container;

                // Getting the inner Linear Layout
                LinearLayout linearLayoutChild = (LinearLayout) linearLayoutParent
                        .getChildAt(0);
                // Getting the inner Linear Layout
                RelativeLayout relativeLayoutChild = (RelativeLayout) linearLayoutParent
                        .getChildAt(1);

                // Getting the Country TextView
                TextView tv_title = (TextView) relativeLayoutChild
                        .getChildAt(0);
                TextView startTime = (TextView) linearLayoutChild
                        .getChildAt(0);
                TextView endTime = (TextView) linearLayoutChild
                        .getChildAt(1);

                String mTitle = tv_title.getText().toString();
                String mstartTime = startTime.getText().toString();

                String mendTime = endTime.getText().toString();

                Intent intent = new Intent(getActivity(), EventDetail.class);
                intent.putExtra("title", mTitle);
                intent.putExtra("starttime", mstartTime);
                intent.putExtra("endtime", mendTime);
                startActivity(intent);
                Toast.makeText(getActivity(),
                        mTitle + " " + mstartTime + " " + mendTime,
                        Toast.LENGTH_SHORT).show();
            }
        };
        listview.setOnItemClickListener(itemClickListener);
    }
}

public void onStart() {
    super.onStart();

}

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    // TODO Auto-generated method stub

}

}

Upvotes: 0

Views: 348

Answers (1)

Moubeen Farooq Khan
Moubeen Farooq Khan

Reputation: 2885

Whay you can do in your adapter class is to override below function

@Override
public boolean isEnabled(int position) {


  // here you can implement logic and can return true and false
  // if you will return true then row will be clickable 
  // if you return false the row will be not clickable        

    return true;
}

Upvotes: 1

Related Questions