Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 自定义ListView在片段中不可单击_Java_Android_Listview_Android Fragments_Fragment - Fatal编程技术网

Java 自定义ListView在片段中不可单击

Java 自定义ListView在片段中不可单击,java,android,listview,android-fragments,fragment,Java,Android,Listview,Android Fragments,Fragment,我在一个viewpager中有一个片段,该片段有一个listview,它应该从mysql表中提取数据并将它们插入listview,问题是列表中的行不可单击,就好像它是行的图像一样 package test.example.com.test; import android.app.ProgressDialog; import android.os.AsyncTask; import android.os.Bundle;

我在一个viewpager中有一个片段,该片段有一个listview,它应该从mysql表中提取数据并将它们插入listview,问题是列表中的行不可单击,就好像它是行的图像一样

        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);
            }
        });

    }

}

}
package test.example.com.test;
导入android.app.ProgressDialog;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.support.v4.app.Fragment;
导入android.util.Log;
导入android.view.LayoutInflater;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.AdapterView;
导入android.widget.ImageButton;
导入android.widget.ListAdapter;
导入android.widget.ListView;
导入android.widget.simpledapter;
导入android.widget.TextView;
导入android.widget.Toast;
导入org.apache.http.NameValuePair;
导入org.json.JSONArray;
导入org.json.JSONException;
导入org.json.JSONObject;
导入java.util.ArrayList;
导入java.util.HashMap;
导入java.util.List;
公共类FragmentCtab3扩展了Fragment{
//simpledapter-sAdapter;
列表视图需求;
字符串电子邮件,CompId,用户名;
//进度对话框
私人对话;
//创建JSON解析器对象
JSONParser jParser=新的JSONParser();
ArrayList需求列表;
//获取所有产品列表的url
私有静态字符串列表\u COMP\u URL=”http://eshteghel.southlebanon.net/lvCompany.php";
//JSON节点名称
私有静态最终字符串标记_SUCCESS=“SUCCESS”;
私有静态最终字符串标记_DEMANDS=“DEMANDS”;
私有静态最终字符串标记_NAME=“NAME”;
私有静态最终字符串标记\u EMAIL=“EMAIL”;
私有静态最终字符串标记_DESCRIPTION=“DESCRIPTION”;
专用静态最终字符串标记_PHONE=“PHONE”;
私有静态最终字符串标记_GENDER=“GENDER”;
专用静态最终字符串标记_MAJOR=“MAJOR”;
私有静态最终字符串标记_EXPERIENCE=“EXPERIENCE”;
私有静态最终字符串TAG_SALARY=“SALARY”;
私有静态最终字符串TAG_REGION=“REGION”;
//产品JSONArray
JSONArray需求=null;
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
视图根视图=充气机。充气(R.layout.fragment\u company\u tab3,容器,false);
DemandList=新的ArrayList();
新建LoadAllRequired().execute();
//lv=(ListView)getActivity().findViewById(R.id.lvDemand);
lvDemand=(ListView)rootView.findviewbyd(R.id.lvDemand);
lvDemand.setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父级、视图、,
内部位置,长id){
//从选定的ListItem获取值
ImageButton b=(ImageButton)view.findViewById(R.id.btlsSendMail);
字符串ColName=((TextView)view.findViewById(R.id.ColName)).getText()
.toString();
Toast.makeText(getActivity(),ColName,Toast.LENGTH_LONG).show();
Log.d(“所有作业:,“日志”);
b、 setOnClickListener(新视图。OnClickListener(){
@凌驾
公共void onClick(视图v){
Toast.makeText(getActivity(),“Toast”,Toast.LENGTH_LONG.show();
Log.d(“所有作业:,“日志”);
}
});
}
});
字符串myValue=container.getTag().toString();
字符串凭据[]=myValue.split(“”);
用户名=凭据[0];
电子邮件=凭证[1];
//CompId=凭证[2];
返回rootView;
}
类LoadAllAsyncTask{
/**
*在启动后台线程显示进度对话框之前
* */
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
pDialog=newprogressdialog(getActivity());
setMessage(“正在加载作业,请稍候…”);
pDialog.setUndeterminate(假);
pDialog.setCancelable(假);
pDialog.show();
}
/**
*从url获取所有产品
* */
受保护的字符串doInBackground(字符串…args){
//建筑参数
List params=new ArrayList();
//从URL获取JSON字符串
JSONObject json=jParser.makeHttpRequest(LIST_COMP_URL,“GET”,params);
//检查日志cat中的JSON响应
Log.d(“所有作业:,json.toString());
试一试{
//检查成功标签
int success=json.getInt(TAG_success);
如果(成功==1){
//发现的产品
//获取一系列产品
demands=json.getJSONArray(TAG_demands);
//在所有产品中循环
对于(int i=0;ivalue
map.put(标签名称,ColName);
//地图放置(标签、电子邮件、电子邮件);
地图放置(标签描述,描述);
//将哈希列表添加到ArrayList
demandsList.add(map);
}
}否则{
//没有发现任何产品
//启动添加新产品活动
/*意图i=新意图(getApplicationContext(),
NewProductActivity.class);
//关闭以前的所有活动
i、 广告
            <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"
    />