-1

i have a fragment inside a viewpager, the fragment has a listview and it is supposed to pull data from mysql table and insert them into the listview, the problem is that the rows in the list are not clickable, it's as if it's an image of rows.

        package test.example.com.test;

        import android.app.ProgressDialog;
        import android.os.AsyncTask;
        import android.os.Bundle;
        import android.support.v4.app.Fragment;
        import android.util.Log;
        import android.view.LayoutInflater;
        import android.view.View;
        import android.view.ViewGroup;
        import android.widget.AdapterView;
        import android.widget.ImageButton;
        import android.widget.ListAdapter;
        import android.widget.ListView;
        import android.widget.SimpleAdapter;
        import android.widget.TextView;
        import android.widget.Toast;

        import org.apache.http.NameValuePair;
        import org.json.JSONArray;
        import org.json.JSONException;
        import org.json.JSONObject;

        import java.util.ArrayList;
        import java.util.HashMap;
        import java.util.List;

    public class FragmentCtab3 extends Fragment {

//SimpleAdapter sAdapter;
ListView lvDemand;
String Email,CompId,UserName;
// Progress Dialog
private ProgressDialog pDialog;

// Creating JSON Parser object
JSONParser jParser = new JSONParser();

ArrayList<HashMap<String, String>> demandsList;

// url to get all products list
private static String LIST_COMP_URL = "http://eshteghel.southlebanon.net/lvCompany.php";
// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_DEMANDS = "demands";
private static final String TAG_NAME= "Name";
private static final String TAG_EMAIL = "Email";
private static final String TAG_DESCRIPTION = "Description";
private static final String TAG_PHONE = "Phone";
private static final String TAG_GENDER = "Gender";
private static final String TAG_MAJOR= "Major";
private static final String TAG_EXPERIENCE = "Experience";
private static final String TAG_SALARY = "Salary";
private static final String TAG_REGION = "Region";
// products JSONArray
JSONArray demands = null;


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_company_tab3, container, false);
    demandsList = new ArrayList<HashMap<String, String>>();

    new LoadAllDemanded().execute();

    //lv = (ListView) getActivity().findViewById(R.id.lvDemand);
    lvDemand = (ListView) rootView.findViewById(R.id.lvDemand);



    lvDemand.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                                int position, long id) {
            // getting values from selected ListItem
            ImageButton b = (ImageButton) view.findViewById(R.id.btlsSendMail);
            String ColName = ((TextView) view.findViewById(R.id.ColName)).getText()
                    .toString();

            Toast.makeText(getActivity(),ColName, Toast.LENGTH_LONG).show();
            Log.d("All Jobs: ","Log");
            b.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(getActivity(),"TOAST", Toast.LENGTH_LONG).show();
                    Log.d("All Jobs: ", "Log");
                }
            });
        }
    });
    String myValue = container.getTag().toString();
    String credentials[] = myValue.split(" ");
    UserName = credentials[0];
    Email = credentials[1];
    //CompId = credentials[2];

    return rootView;
}

class LoadAllDemanded extends AsyncTask<String, String, String> {

    /**
     * Before starting background thread Show Progress Dialog
     * */
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(getActivity());
        pDialog.setMessage("Loading Jobs. Please wait...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);
        pDialog.show();
    }

    /**
     * getting All products from url
     * */
    protected String doInBackground(String... args) {
        // Building Parameters
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        // getting JSON string from URL
        JSONObject json = jParser.makeHttpRequest(LIST_COMP_URL, "GET", params);

        // Check your log cat for JSON reponse
        Log.d("All Jobs: ", json.toString());

        try {
            // Checking for SUCCESS TAG
            int success = json.getInt(TAG_SUCCESS);

            if (success == 1) {
                // products found
                // Getting Array of Products
                demands = json.getJSONArray(TAG_DEMANDS);

                // looping through All Products
                for (int i = 0; i < demands.length(); i++) {
                    JSONObject c = demands.getJSONObject(i);

                    // Storing each json item in variable
                    String ColName = c.getString(TAG_NAME);
                   // String Email = c.getString(TAG_EMAIL);
                    String Description = c.getString(TAG_DESCRIPTION);

                    // creating new HashMap
                    HashMap<String, String> map = new HashMap<String, String>();

                    // adding each child node to HashMap key => value
                    map.put(TAG_NAME, ColName);
                    //map.put(TAG_EMAIL, Email);
                    map.put(TAG_DESCRIPTION, Description);

                    // adding HashList to ArrayList
                    demandsList.add(map);
                }
            } else {
                // no products found
                // Launch Add New product Activity
                /*Intent i = new Intent(getApplicationContext(),
                        NewProductActivity.class);
                // Closing all previous activities
                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(i);*/

                Toast.makeText(getActivity(),"No jobs Found", Toast.LENGTH_LONG).show();
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }

    /**
     * After completing background task Dismiss the progress dialog
     * **/
    protected void onPostExecute(String file_url) {
        // dismiss the dialog after getting all products
        pDialog.dismiss();
        // updating UI from Background Thread
        getActivity().runOnUiThread(new Runnable() {
            public void run() {
                /**
                 * Updating parsed JSON data into ListView
                 * */
                ListAdapter adapter = new SimpleAdapter(
                        getActivity(), demandsList,
                        R.layout.custom_layout, new String[]{TAG_NAME,
                        /*TAG_EMAIL,*/ TAG_DESCRIPTION},
                        new int[]{R.id.ColName,R.id.ColDescription});
                // updating listview
                lvDemand.setAdapter(adapter);
            }
        });

    }

}

}

and here's the layout code

            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="50dp"
>

<TextView
    android:id="@+id/ColName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:focusable="false"
    android:text="Name"/>


<TextView
    android:id="@+id/ColDescription"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:focusable="false"
    android:text="Description"/>


<ImageButton
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:src="@drawable/mail2"
    android:focusable="false"
    android:layout_gravity="right"
    android:id="@+id/btlsSendMail"
    />

1 Answers1

0

Try to set the choice mode on your ListView object:

  • none 0 Normal list that does not indicate choices.
  • singleChoice 1 The list allows up to one choice.
  • multipleChoice 2 The list allows multiple choices.
  • multipleChoiceModal 3 The list allows multiple choices in a custom selection mode.

Guide

user3290180
  • 4,260
  • 9
  • 42
  • 77