亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android開(kāi)發(fā)實(shí)現(xiàn)AlertDialog中View的控件設(shè)置監(jiān)聽(tīng)功能分析

 更新時(shí)間:2017年11月28日 14:35:14   作者:zml_2015  
這篇文章主要介紹了Android開(kāi)發(fā)實(shí)現(xiàn)AlertDialog中View的控件設(shè)置監(jiān)聽(tīng)功能,結(jié)合實(shí)例形式分析了Android針對(duì)AlertDialog中的控件使用View進(jìn)行監(jiān)聽(tīng)的相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Android開(kāi)發(fā)實(shí)現(xiàn)AlertDialog中View的控件設(shè)置監(jiān)聽(tīng)功能。分享給大家供大家參考,具體如下:

之前給彈出的AlertDialog中的控件設(shè)置監(jiān)聽(tīng)時(shí),老是報(bào)空指針異常,之所以報(bào)空指針異常,是因?yàn)槲襢indViewById寫(xiě)的有問(wèn)題,因?yàn)槲覀冃枰o彈出框中的控件設(shè)置監(jiān)聽(tīng),直接用findViewById是找不到彈出框中的控件的,需要利用Dialog.findViewById或者利用你找到的彈出框中的View,然后view.findViewById;具體看下面代碼

package com.example.mydialog;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;
/**
 * @author 鄭明亮
 * @date 2015-11-4 下午1:57:31
 * @version 1.0
 */
public class secondActivity extends Activity implements OnClickListener {
  Button btshow,bt_emial,bt_blog;
  ImageButton btcancel;
  @Override
  public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.second);
    final AlertDialog dialog=new AlertDialog.Builder(secondActivity.this).create();
    dialog.show();
    dialog.getWindow().setContentView(R.layout.myxml);//重點(diǎn)看這獲取彈出框內(nèi)的視圖view
    // btshow=(Button) findViewById(R.id.bt_show);
    btcancel = (ImageButton) dialog.findViewById(R.id.bt_cancel);//重點(diǎn)看這行的Dialog
    bt_blog=(Button) dialog.findViewById(R.id.bt_blog);
    bt_emial=(Button) dialog.findViewById(R.id.bt_email);
     bt_blog.setOnClickListener(this);
     bt_emial.setOnClickListener(this);
    btcancel.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View arg0) {
      dialog.dismiss();
      Toast.makeText(secondActivity.this, "clicked", 0).show();
      Log.e("log", "click");
    }
     });
  }
  @Override
  public void onClick(View arg0) {
    switch (arg0.getId()) {
    case R.id.bt_blog:
      Uri uri = Uri.parse("http://chabaoo.cn");
      Intent it = new Intent(Intent.ACTION_VIEW, uri);
      startActivity(it);
      break;
    case R.id.bt_email:
      Uri uri1 = Uri.parse("http://chabaoo.cn");
      Intent it1 = new Intent(Intent.ACTION_VIEW, uri1);
      startActivity(it1);
      break;
    default:
      break;
    }
  }
}

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開(kāi)發(fā)入門(mén)與進(jìn)階教程》、《Android調(diào)試技巧與常見(jiàn)問(wèn)題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論