setOnItemClickListener不工作在列表视图的android [英] setOnItemClickListener is not working in list-view android

查看:144
本文介绍了setOnItemClickListener不工作在列表视图的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过点击其上的列表视图加载列表项移动到其他活动,但我不为什么它没有移动到任何其他活动时,我点击任何一个列表项什么也没有发生任何碰撞,没有移动到其他活动无关。可在任何一帮我请。

我搜索很多,有这么多的解决方案,但任何解决方案的不工作在我的情况。请在下面帮我活动code。

 公共类Classes_Ext_DB扩展活动实现OnClickListener {

ImageView的imageViewNewClass,imageViewDelete;
ListView控件mListView;

/ **滑动菜单* /
布尔alreadyShowing = FALSE;
私人诠释WINDOWWIDTH;
民营动画animationClasses;
私人RelativeLayout的classesSlider;
LayoutInflater layoutInflaterClasses;
ArrayAdapter< CharSequence的> adapterSpinner;

私人ProgressDialog pDialog;
//创建JSON解析器对象
JSONParser jParser =新JSONParser();

ArrayList的< HashMap的<字符串,字符串>> productsList;

// URL获得所有产品列表
私有静态字符串url_all_classDetail =服务器细节/ get_all_classdetail.php;

// URL删除产品
私有静态最后弦乐url_delete_class =服务器细节/ delete_class.php;

// JSON节点名称
私有静态最后弦乐TAG_SUCCESS =成功;
私有静态最后弦乐TAG_PRODUCTS =产品;
私有静态最后弦乐TAG_ID =ID;
私有静态最后弦乐TAG_CLASSNAME =将class_name;

//产品JSONArray
JSONArray产品= NULL;

@燮pressWarnings(德precation)
@覆盖
公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.classes);

    imageViewNewClass =(ImageView的)findViewById(R.id.newclass);
    imageViewDelete =(ImageView的)findViewById(R.id.deletemenu);
    mListView =(ListView控件)findViewById(R.id.displaydata);

    productsList =新的ArrayList< HashMap的<字符串,字符串>>();

    显示显示= getWindowManager()getDefaultDisplay()。
    WINDOWWIDTH = display.getWidth();
    display.getHeight();
    layoutInflaterClasses =(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    mListView.setOnItemClickListener(新AdapterView.OnItemClickListener(){
        @覆盖
        公共无效onItemClick(适配器视图<>父,查看项目,
                INT位置,长的id){
            意图mIntent =新的意图(Classes_Ext_DB.this,
                    RecordAudio.class);
            startActivity(mIntent);
        }
    });

    新LoadAllClassDetail()执行();

    imageViewNewClass.setOnClickListener(新View.OnClickListener(){
        公共无效的onClick(视图v){
            意向意图=新的意图(Classes_Ext_DB.this,
                    Class_Create_Ext_DB.class);
            startActivityForResult(意向,100);
        }
    });

    imageViewDelete.setOnClickListener(新OnClickListener(){
        @覆盖
        公共无效的onClick(查看为arg0){
            AlertDialog.Builder alertDialog =新AlertDialog.Builder(
                    Classes_Ext_DB.this);

            最后的微调spinnerDelete =新的微调(Classes_Ext_DB.this);
            alertDialog.setView(spinnerDelete);

            adapterSpinner = ArrayAdapter.createFromResource(
                    Classes_Ext_DB.this,R.array.delete_menu,
                    android.R.layout.simple_spinner_item);
            adapterSpinner
                    .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinnerDelete.setAdapter(adapterSpinner);

            alertDialog.setPositiveButton(OK,
                    新DialogInterface.OnClickListener(){
                        公共无效的onClick(DialogInterface对话框,
                                其中INT){
                            如果(spinnerDelete.getSelectedItemPosition()== 0){
                                新DeleteProduct()执行()。
                            }
                        }
                    });
            alertDialog.setNegativeButton(取消,
                    新DialogInterface.OnClickListener(){
                        公共无效的onClick(DialogInterface对话框,
                                其中INT){
                            dialog.cancel();
                        }
                    });
            alertDialog.show();

        }
    });

    findViewById(R.id.skirrmenu).setOnClickListener(新OnClickListener(){
        @覆盖
        公共无效的onClick(视图v){
            如果(!alreadyShowing){
                alreadyShowing = TRUE;
                openSlidingMenu();
            }
        }
    });
}

@覆盖
保护无效onActivityResult(INT申请code,INT结果code,意图数据){
    super.onActivityResult(要求code,因此code,数据);
    //如果结果是code 100,然后通过再次重装活动加载项
    如果(结果code == 100){
        意向意图= getIntent();
        完();
        startActivity(意向);
    }
}

类LoadAllClassDetail扩展的AsyncTask<字符串,字符串,字符串> {

    / **
     *在启动后台线程显示进度对话框
     * * /
    @覆盖
    在preExecute保护无效(){
        super.on preExecute();
        pDialog =新ProgressDialog(Classes_Ext_DB.this);
        pDialog.setMessage(加载类请稍候...);
        pDialog.setIndeterminate(假);
        pDialog.setCancelable(假);
        pDialog.show();
    }

    / **
     *得到所有产品的网址
     * * /
    保护字符串doInBackground(字符串参数... args){
        //大厦参数
        名单<的NameValuePair> PARAMS =新的ArrayList<的NameValuePair>();
        //从URL获取JSON字符串
        JSONObject的JSON = jParser.makeHtt prequest(url_all_classDetail,
                GET,则params);

        //检查你的日志猫JSON效应初探
        Log.d(所有类,json.toString());

        尝试 {
            //检查成功TAG
            INT成功= json.getInt(TAG_SUCCESS);
            如果(成功== 1){
                发现//产品
                //获取产品阵列
                产品= json.getJSONArray(TAG_PRODUCTS);

                //遍历所有产品
                的for(int i = 0; I< products.length();我++){
                    JSONObject的C = products.getJSONObject(我);

                    //保存在变量中的每个JSON项目
                    串CID = c.getString(TAG_ID);
                    字符串CN = c.getString(TAG_CLASSNAME);

                    //创建新的HashMap
                    HashMap的<字符串,字符串>图=新的HashMap<字符串,字符串>();

                    //添加每个子节点HashMap中的key =>值
                    map.put(tag_id,分别CID);
                    map.put(TAG_CLASSNAME,CN);

                    //添加HashList到ArrayList中
                    productsList.add(图)
                }
            } 其他 {
                //没有发现产品
                //启动添加新产品活动
                意图I =新的意图(getApplicationContext()
                        Class_Create_Ext_DB.class);
                //关闭所有previous活动
                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(ⅰ);
            }
        }赶上(JSONException E){
            e.printStackTrace();
        }
        返回null;
    }

    / **
     *在完成后台任务之后关闭该进度对话框
     * ** /
    保护无效onPostExecute(字符串file_url){

        让所有的产品之后//关闭该对话框
        pDialog.dismiss();

        //从后台线程更新UI
        runOnUiThread(新的Runnable(){
            公共无效的run(){

                / **
                 *更新解析JSON数据到ListView控件
                 * * /
                ListAdapter适配器=新SimpleAdapter(
                        Classes_Ext_DB.this,productsList,
                        R.layout.custom_class,新的String [] {
                                TAG_CLASSNAME,TAG_ID},
                        新的INT [] {R.id.classname});
                mListView.setAdapter(适配器);
                mListView.setCacheColorHint(Color.TRANSPARENT);
            }
        });
    }
}

/ ******************* ****************
 *背景异步任务删​​除类
 * * /
类DeleteProduct扩展的AsyncTask<字符串,字符串,字符串> {

    / **
     *在启动后台线程显示进度对话框
     * * /

    @覆盖
    在preExecute保护无效(){
        super.on preExecute();
        pDialog =新ProgressDialog(Classes_Ext_DB.this);
        pDialog.setMessage(删除类......请稍候......);
        pDialog.setIndeterminate(假);
        pDialog.setCancelable(真正的);
        pDialog.show();
    }

    / **
     *删除产品
     * * /
    保护字符串doInBackground(字符串参数... args){

        //检查成功标签
        诠释成功;
        尝试 {
            //大厦参数
            名单<的NameValuePair> PARAMS =新的ArrayList<的NameValuePair>();
            params.add(新BasicNameValuePair(ID,TAG_ID));

            //获取产品的详细信息通过HTTP请求
            JSONObject的JSON = jParser.makeHtt prequest(url_delete_class,
                    POST,则params);
            //检查你的日志,JSON响应
            Log.d(删除产品,json.toString());
            // json的成功标签
            成功= json.getInt(TAG_SUCCESS);
            如果(成功== 1){
            }
        }赶上(JSONException E){
            e.printStackTrace();
        }
        返回null;
    }

    / **
     *在完成后台任务之后关闭该进度对话框
     * ** /
    保护无效onPostExecute(字符串file_url){
        pDialog.dismiss();
    }
}

私人无效openSlidingMenu(){
    // showFadePopup();
    INT宽度=(INT)(WINDOWWIDTH * 0.8f);
    translateView((浮动)(宽));
    @燮pressWarnings(德precation)
    INT高= LayoutParams.FILL_PARENT;
    //创建一个弹出
    最后查看布局= layoutInflaterClasses.inflate(
            R.layout.option_popup_layout,
            (ViewGroup中)findViewById(R.id.popup_element));

    ImageView的imageViewassignment =(ImageView的)布局
            .findViewById(R.id.assignment);
    imageViewassignment.setOnClickListener(本);

    ImageView的imageViewfacebook =(ImageView的)布局
            .findViewById(R.id.likefb);
    imageViewfacebook.setOnClickListener(本);

    ImageView的imageViewTwitter =(ImageView的)布局
            .findViewById(R.id.twitter);
    imageViewTwitter.setOnClickListener(本);

    ImageView的imageViewBattery =(ImageView的)布局
            .findViewById(R.id.battery);
    imageViewBattery.setOnClickListener(本);

    ImageView的imageViewAudio =(ImageView的)layout.findViewById(R.id.audio);
    imageViewAudio.setOnClickListener(本);

    ImageView的imageViewTakeNotes =(ImageView的)布局
            .findViewById(R.id.takenote);
    imageViewTakeNotes.setOnClickListener(本);

    ImageView的imageViewAllNotes =(ImageView的)布局
            .findViewById(R.id.allnotes);
    imageViewAllNotes.setOnClickListener(本);

    ImageView的imageViewReportBug =(ImageView的)布局
            .findViewById(R.id.reportbug);
    imageViewReportBug.setOnClickListener(本);

    ImageView的imageViewFeedback =(ImageView的)布局
            .findViewById(R.id.feedback);
    imageViewFeedback.setOnClickListener(本);

    最后PopupWindow optionsPopup =新PopupWindow(布局,宽度,高度,
            真正);
    optionsPopup.setBackgroundDrawable(新PaintDrawable());
    optionsPopup.showAtLocation(布局,Gravity.NO_GRAVITY,0,0);
    optionsPopup.setOnDismissListener(新PopupWindow.OnDismissListener(){
        公共无效onDismiss(){
            //以清除在previous动画过渡
            清理(​​);
            //移动的观点出
            translateView(0);
            //清除最新的动画过渡出
            清理(​​);
            //重新设置变量
            alreadyShowing = FALSE;
        }
    });
}

公共无效的onClick(视图v){
    开关(v.getId()){
    案例R.id.assignment:
        意图分配=新的意图(Classes_Ext_DB.this,Assignment.class);
        startActivity(分配);
        打破;

    案例R.id.likefb:
        Facebook的意图=新的意图(Classes_Ext_DB.this,
                FacebookLogin.class);
        startActivity(脸谱);
        打破;

    案例R.id.facebooklogin:
        Twitter的意图=新的意图(Classes_Ext_DB.this,TwitterLogin.class);
        startActivity特(Twitter);
        打破;

    案例R.id.battery:
        AlertDialog.Builder myDialogBattery =新AlertDialog.Builder(
                Classes_Ext_DB.this);
        myDialogBattery.setTitle(如何使用较少的电池);

        TextView的textViewBattery =新的TextView(Classes_Ext_DB.this);
        ImageView的imageViewBattery =新ImageView的(Classes_Ext_DB.this);

        imageViewBattery.setImageResource(R.drawable.batteryicon);
        textViewBattery
                .setText(用电池可能较少量的最好办法是降低设备的亮度级别);
        textViewBattery.setTextColor(Color.GRAY);
        textViewBattery.setTextSize(20);
        的LayoutParams textViewLayoutParamsBattery =新的LayoutParams(
                LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
        textViewBattery.setLayoutParams(textViewLayoutParamsBattery);

        的LinearLayout layoutBattery =新的LinearLayout(Classes_Ext_DB.this);
        layoutBattery.setOrientation(LinearLayout.VERTICAL);
        layoutBattery.addView(textViewBattery);
        layoutBattery.addView(imageViewBattery);

        myDialogBattery.setView(layoutBattery);
        myDialogBattery.setPositiveButton(OK,
                新DialogInterface.OnClickListener(){
                    //做一些按钮被按下时,
                    公共无效的onClick(DialogInterface为arg0,INT ARG1){
                    }
                });
        myDialogBattery.show();
        打破;

    案例R.id.audio:
        AlertDialog.Builder myDialogAudio =新AlertDialog.Builder(
                Classes_Ext_DB.this);
        myDialogAudio.setTitle(如何获得更好的音频笔记);

        TextView的textViewAudio =新的TextView(Classes_Ext_DB.this);
        ImageView的imageViewAudio =新ImageView的(Classes_Ext_DB.this);

        imageViewAudio.setImageResource(R.drawable.micicon);
        textViewAudio
                .setText(获得最佳声音效果的音频是很重要的,以确保您获得最佳的录音笔记可能始终确保麦克风对着斯皮克斯。);
        textViewAudio.setTextColor(Color.GRAY);
        textViewAudio.setTextSize(20);
        的LayoutParams textViewLayoutParams =新的LayoutParams(
                LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
        textViewAudio.setLayoutParams(textViewLayoutParams);

        的LinearLayout layoutAudio =新的LinearLayout(Classes_Ext_DB.this);
        layoutAudio.setOrientation(LinearLayout.VERTICAL);
        layoutAudio.addView(textViewAudio);
        layoutAudio.addView(imageViewAudio);

        myDialogAudio.setView(layoutAudio);

        myDialogAudio.setPositiveButton(OK,
                新DialogInterface.OnClickListener(){
                    公共无效的onClick(DialogInterface为arg0,INT ARG1){
                    }
                });
        myDialogAudio.show();
        打破;

    案例R.id.takenote:
        意图takenote =新的意图(Classes_Ext_DB.this,
                Classes_Ext_DB.class);
        startActivity(takenote);
        打破;

    案例R.id.allnotes:
        意图allNotes =新的意图(Classes_Ext_DB.this,RecordAudio.class);
        startActivity(allNotes);
        打破;

    案例R.id.reportbug:
        意图reportbug的=新的意图(Classes_Ext_DB.this,ReportBug.class);
        startActivity(reportbug的);
        打破;

    案例R.id.feedback:
        意向反馈=新的意图(Classes_Ext_DB.this,Feedback.class);
        startActivity(反馈);
        打破;
    }
}

私人无效translateView(浮动右){
    animationClasses =新TranslateAnimation(0F,右,0F,0F);
    animationClasses.setDuration(100);
    animationClasses.setFillEnabled(真正的);
    animationClasses.setFillAfter(真正的);

    classesSlider =(RelativeLayout的)findViewById(R.id.classes_slider);
    classesSlider.startAnimation(animationClasses);
    classesSlider.setVisibility(View.VISIBLE);
}

私人无效清除(){
    如果(NULL!= classesSlider){
        classesSlider.clearAnimation();
        classesSlider = NULL;
    }
    如果(NULL!= animationClasses){
        animationClasses.cancel();
        animationClasses = NULL;
    }
}
}
 

修改

与myXML

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:ID =@ + ID / classes_slider
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:背景=@可绘制/ back_bg
机器人:方向=垂直>


< ImageView的
    机器人:ID =@ + ID / headerbar
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentLeft =真
    机器人:layout_alignParentTop =真
    机器人:SRC =@可绘制/ headerbar_small/>

< ImageView的
    机器人:ID =@ + ID / skirrlogo
    机器人:layout_width =100dp
    机器人:layout_height =30dp
    机器人:layout_alignParentTop =真
    机器人:layout_marginLeft =50dp
    机器人:layout_marginTop =10dp
    机器人:SRC =@可绘制/ skirrwhite/>

< ImageView的
    机器人:ID =@ + ID / skirrmenu
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_marginLeft =10dp
    机器人:layout_marginTop =15dp
    机器人:SRC =@可绘制/ slideropener/>

<的TextView
    机器人:ID =@ + ID / textView1
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignBottom =@ + ID / skirrlogo
    机器人:layout_marginLeft =15dp
    机器人:layout_toRightOf =@ + ID / skirrlogo
    机器人:文本=@字符串/ classses
    机器人:textAppearance =机器人:ATTR / textAppearanceMedium
    机器人:TEXTSTYLE =黑体/>

< ImageView的
    机器人:ID =@ + ID /的NewClass
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_below =@ + ID / headerbar
    机器人:layout_centerHorizo​​ntal =真
    机器人:layout_marginTop =14dp
    机器人:SRC =@可绘制/ class_button_new/>

< ImageView的
    机器人:ID =@ + ID / deletemenu
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentRight =真
    机器人:layout_alignTop =@ + ID / skirrlogo
    机器人:SRC =@可绘制/ menubutton_large/>

<的ListView
    机器人:ID =@ + ID / displaydata
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_below =@ + ID /的NewClass>

< / ListView控件>

< / RelativeLayout的>
 

custom_class.xml

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT>

<复选框
    机器人:ID =@ + ID / checkBox1
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT/>

<的TextView
    机器人:ID =@ + ID /类名
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_marginLeft =10dip
    机器人:textAppearance =机器人:ATTR / textAppearanceMedium
    机器人:文字颜色=#000000
    机器人:TEXTSTYLE =黑体/>

< / LinearLayout中>
 

解决方案

问题是,Android不允许您选择有是可聚焦在他们身上的元素列表中的项目。我修改的列表项的复选框有像这样的属性:

 机器人:可调焦=假
 机器人:focusableInTouchMode =假
 

现在我的包含复选框(作品按钮太)是传统意义上的选择列表项(它们亮起来,你可以任意位置单击列表中的项目和onListItemClick处理程序会火,等等)。

I am trying to move to other activity by clicking on list item which is loaded in list-view, but i don't why it is not moving to any other activity when i click on any list item nothing happens no crash, not moving to other activity nothing. Can any-one help me please.

I searched lot and got so many solution but any of the solution is not working in my case. Please help below is my activity code.

public class Classes_Ext_DB extends Activity implements OnClickListener {

ImageView imageViewNewClass, imageViewDelete;
ListView mListView;

/** Sliding Menu */
boolean alreadyShowing = false;
private int windowWidth;
private Animation animationClasses;
private RelativeLayout classesSlider;
LayoutInflater layoutInflaterClasses;
ArrayAdapter<CharSequence> adapterSpinner;

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

ArrayList<HashMap<String, String>> productsList;

// url to get all products list
private static String url_all_classDetail = "server detail/get_all_classdetail.php";

// url to delete product
private static final String url_delete_class = "server-detail/delete_class.php";

// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_PRODUCTS = "products";
private static final String TAG_ID = "ID";
private static final String TAG_CLASSNAME = "class_name";

// products JSONArray
JSONArray products = null;

@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.classes);

    imageViewNewClass = (ImageView) findViewById(R.id.newclass);
    imageViewDelete = (ImageView) findViewById(R.id.deletemenu);
    mListView = (ListView) findViewById(R.id.displaydata);

    productsList = new ArrayList<HashMap<String, String>>();

    Display display = getWindowManager().getDefaultDisplay();
    windowWidth = display.getWidth();
    display.getHeight();
    layoutInflaterClasses = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View item,
                int position, long id) {
            Intent mIntent = new Intent(Classes_Ext_DB.this,
                    RecordAudio.class);
            startActivity(mIntent);
        }
    });

    new LoadAllClassDetail().execute();

    imageViewNewClass.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(Classes_Ext_DB.this,
                    Class_Create_Ext_DB.class);
            startActivityForResult(intent, 100);
        }
    });

    imageViewDelete.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(
                    Classes_Ext_DB.this);

            final Spinner spinnerDelete = new Spinner(Classes_Ext_DB.this);
            alertDialog.setView(spinnerDelete);

            adapterSpinner = ArrayAdapter.createFromResource(
                    Classes_Ext_DB.this, R.array.delete_menu,
                    android.R.layout.simple_spinner_item);
            adapterSpinner
                    .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinnerDelete.setAdapter(adapterSpinner);

            alertDialog.setPositiveButton("Ok",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
                                int which) {
                            if (spinnerDelete.getSelectedItemPosition() == 0) {
                                new DeleteProduct().execute();
                            }
                        }
                    });
            alertDialog.setNegativeButton("Cancel",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
                                int which) {
                            dialog.cancel();
                        }
                    });
            alertDialog.show();

        }
    });

    findViewById(R.id.skirrmenu).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!alreadyShowing) {
                alreadyShowing = true;
                openSlidingMenu();
            }
        }
    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // if result code 100 then load item by reloading activity again
    if (resultCode == 100) {
        Intent intent = getIntent();
        finish();
        startActivity(intent);
    }
}

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

    /**
     * Before starting background thread Show Progress Dialog
     * */
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(Classes_Ext_DB.this);
        pDialog.setMessage("Loading Classes. 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(url_all_classDetail,
                "GET", params);

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

        try {
            // Checking for SUCCESS TAG
            int success = json.getInt(TAG_SUCCESS);
            if (success == 1) {
                // products found
                // Getting Array of Products
                products = json.getJSONArray(TAG_PRODUCTS);

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

                    // Storing each json item in variable
                    String cid = c.getString(TAG_ID);
                    String cn = c.getString(TAG_CLASSNAME);

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

                    // adding each child node to HashMap key => value
                    map.put(TAG_ID, cid);
                    map.put(TAG_CLASSNAME, cn);

                    // adding HashList to ArrayList
                    productsList.add(map);
                }
            } else {
                // no products found
                // Launch Add New product Activity
                Intent i = new Intent(getApplicationContext(),
                        Class_Create_Ext_DB.class);
                // Closing all previous activities
                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(i);
            }
        } 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
        runOnUiThread(new Runnable() {
            public void run() {

                /**
                 * Updating parsed JSON data into ListView
                 * */
                ListAdapter adapter = new SimpleAdapter(
                        Classes_Ext_DB.this, productsList,
                        R.layout.custom_class, new String[] {
                                TAG_CLASSNAME, TAG_ID },
                        new int[] { R.id.classname });
                mListView.setAdapter(adapter);
                mListView.setCacheColorHint(Color.TRANSPARENT);
            }
        });
    }
}

/*****************************************************************
 * Background Async Task to Delete Class
 * */
class DeleteProduct extends AsyncTask<String, String, String> {

    /**
     * Before starting background thread Show Progress Dialog
     * */

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(Classes_Ext_DB.this);
        pDialog.setMessage("Deleting Class... Please wait...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();
    }

    /**
     * Deleting product
     * */
    protected String doInBackground(String... args) {

        // Check for success tag
        int success;
        try {
            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("ID", TAG_ID));

            // getting product details by making HTTP request
            JSONObject json = jParser.makeHttpRequest(url_delete_class,
                    "POST", params);
            // check your log for json response
            Log.d("Delete Product", json.toString());
            // json success tag
            success = json.getInt(TAG_SUCCESS);
            if (success == 1) {
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * After completing background task Dismiss the progress dialog
     * **/
    protected void onPostExecute(String file_url) {
        pDialog.dismiss();
    }
}

private void openSlidingMenu() {
    // showFadePopup();
    int width = (int) (windowWidth * 0.8f);
    translateView((float) (width));
    @SuppressWarnings("deprecation")
    int height = LayoutParams.FILL_PARENT;
    // creating a popup
    final View layout = layoutInflaterClasses.inflate(
            R.layout.option_popup_layout,
            (ViewGroup) findViewById(R.id.popup_element));

    ImageView imageViewassignment = (ImageView) layout
            .findViewById(R.id.assignment);
    imageViewassignment.setOnClickListener(this);

    ImageView imageViewfacebook = (ImageView) layout
            .findViewById(R.id.likefb);
    imageViewfacebook.setOnClickListener(this);

    ImageView imageViewTwitter = (ImageView) layout
            .findViewById(R.id.twitter);
    imageViewTwitter.setOnClickListener(this);

    ImageView imageViewBattery = (ImageView) layout
            .findViewById(R.id.battery);
    imageViewBattery.setOnClickListener(this);

    ImageView imageViewAudio = (ImageView) layout.findViewById(R.id.audio);
    imageViewAudio.setOnClickListener(this);

    ImageView imageViewTakeNotes = (ImageView) layout
            .findViewById(R.id.takenote);
    imageViewTakeNotes.setOnClickListener(this);

    ImageView imageViewAllNotes = (ImageView) layout
            .findViewById(R.id.allnotes);
    imageViewAllNotes.setOnClickListener(this);

    ImageView imageViewReportBug = (ImageView) layout
            .findViewById(R.id.reportbug);
    imageViewReportBug.setOnClickListener(this);

    ImageView imageViewFeedback = (ImageView) layout
            .findViewById(R.id.feedback);
    imageViewFeedback.setOnClickListener(this);

    final PopupWindow optionsPopup = new PopupWindow(layout, width, height,
            true);
    optionsPopup.setBackgroundDrawable(new PaintDrawable());
    optionsPopup.showAtLocation(layout, Gravity.NO_GRAVITY, 0, 0);
    optionsPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
        public void onDismiss() {
            // to clear the previous animation transition in
            cleanUp();
            // move the view out
            translateView(0);
            // to clear the latest animation transition out
            cleanUp();
            // resetting the variable
            alreadyShowing = false;
        }
    });
}

public void onClick(View v) {
    switch (v.getId()) {
    case R.id.assignment:
        Intent assign = new Intent(Classes_Ext_DB.this, Assignment.class);
        startActivity(assign);
        break;

    case R.id.likefb:
        Intent facebook = new Intent(Classes_Ext_DB.this,
                FacebookLogin.class);
        startActivity(facebook);
        break;

    case R.id.facebooklogin:
        Intent twitter = new Intent(Classes_Ext_DB.this, TwitterLogin.class);
        startActivity(twitter);
        break;

    case R.id.battery:
        AlertDialog.Builder myDialogBattery = new AlertDialog.Builder(
                Classes_Ext_DB.this);
        myDialogBattery.setTitle("How to use Less Battery");

        TextView textViewBattery = new TextView(Classes_Ext_DB.this);
        ImageView imageViewBattery = new ImageView(Classes_Ext_DB.this);

        imageViewBattery.setImageResource(R.drawable.batteryicon);
        textViewBattery
                .setText("The best way to use less amount of battery possible is to lower the brightness level on your device");
        textViewBattery.setTextColor(Color.GRAY);
        textViewBattery.setTextSize(20);
        LayoutParams textViewLayoutParamsBattery = new LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        textViewBattery.setLayoutParams(textViewLayoutParamsBattery);

        LinearLayout layoutBattery = new LinearLayout(Classes_Ext_DB.this);
        layoutBattery.setOrientation(LinearLayout.VERTICAL);
        layoutBattery.addView(textViewBattery);
        layoutBattery.addView(imageViewBattery);

        myDialogBattery.setView(layoutBattery);
        myDialogBattery.setPositiveButton("OK",
                new DialogInterface.OnClickListener() {
                    // do something when the button is clicked
                    public void onClick(DialogInterface arg0, int arg1) {
                    }
                });
        myDialogBattery.show();
        break;

    case R.id.audio:
        AlertDialog.Builder myDialogAudio = new AlertDialog.Builder(
                Classes_Ext_DB.this);
        myDialogAudio.setTitle("How to get better audio notes");

        TextView textViewAudio = new TextView(Classes_Ext_DB.this);
        ImageView imageViewAudio = new ImageView(Classes_Ext_DB.this);

        imageViewAudio.setImageResource(R.drawable.micicon);
        textViewAudio
                .setText("Getting the best sounding audio is important, to make sure you are getting the best audio notes possible always ensure that the microphone is facing the speakes.");
        textViewAudio.setTextColor(Color.GRAY);
        textViewAudio.setTextSize(20);
        LayoutParams textViewLayoutParams = new LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        textViewAudio.setLayoutParams(textViewLayoutParams);

        LinearLayout layoutAudio = new LinearLayout(Classes_Ext_DB.this);
        layoutAudio.setOrientation(LinearLayout.VERTICAL);
        layoutAudio.addView(textViewAudio);
        layoutAudio.addView(imageViewAudio);

        myDialogAudio.setView(layoutAudio);

        myDialogAudio.setPositiveButton("OK",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface arg0, int arg1) {
                    }
                });
        myDialogAudio.show();
        break;

    case R.id.takenote:
        Intent takenote = new Intent(Classes_Ext_DB.this,
                Classes_Ext_DB.class);
        startActivity(takenote);
        break;

    case R.id.allnotes:
        Intent allNotes = new Intent(Classes_Ext_DB.this, RecordAudio.class);
        startActivity(allNotes);
        break;

    case R.id.reportbug:
        Intent reportBug = new Intent(Classes_Ext_DB.this, ReportBug.class);
        startActivity(reportBug);
        break;

    case R.id.feedback:
        Intent feedback = new Intent(Classes_Ext_DB.this, Feedback.class);
        startActivity(feedback);
        break;
    }
}

private void translateView(float right) {
    animationClasses = new TranslateAnimation(0f, right, 0f, 0f);
    animationClasses.setDuration(100);
    animationClasses.setFillEnabled(true);
    animationClasses.setFillAfter(true);

    classesSlider = (RelativeLayout) findViewById(R.id.classes_slider);
    classesSlider.startAnimation(animationClasses);
    classesSlider.setVisibility(View.VISIBLE);
}

private void cleanUp() {
    if (null != classesSlider) {
        classesSlider.clearAnimation();
        classesSlider = null;
    }
    if (null != animationClasses) {
        animationClasses.cancel();
        animationClasses = null;
    }
}
}

Edit

MyXML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/classes_slider"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/back_bg"
android:orientation="vertical" >


<ImageView
    android:id="@+id/headerbar"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:src="@drawable/headerbar_small" />

<ImageView
    android:id="@+id/skirrlogo"
    android:layout_width="100dp"
    android:layout_height="30dp"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="50dp"
    android:layout_marginTop="10dp"
    android:src="@drawable/skirrwhite" />

<ImageView
    android:id="@+id/skirrmenu"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="15dp"
    android:src="@drawable/slideropener" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/skirrlogo"
    android:layout_marginLeft="15dp"
    android:layout_toRightOf="@+id/skirrlogo"
    android:text="@string/classses"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textStyle="bold" />

<ImageView
    android:id="@+id/newclass"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/headerbar"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="14dp"
    android:src="@drawable/class_button_new" />

<ImageView
    android:id="@+id/deletemenu"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignTop="@+id/skirrlogo"
    android:src="@drawable/menubutton_large" />

<ListView
    android:id="@+id/displaydata"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/newclass" >

</ListView>

</RelativeLayout>

custom_class.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<CheckBox
    android:id="@+id/checkBox1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/classname"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dip"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="#000000"
    android:textStyle="bold" />

</LinearLayout>

解决方案

The issue is that Android doesn't allow you to select list items that have elements on them that are focusable. I modified the checkbox on the list item to have an attribute like so:

 android:focusable="false"
 android:focusableInTouchMode="false"

Now my list items that contain checkboxes (works for buttons too) are "selectable" in the traditional sense (they light up, you can click anywhere in the list item and the "onListItemClick" handler will fire, etc).

这篇关于setOnItemClickListener不工作在列表视图的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆